首页 > 解决方案 > Firestore .set 不保存来自 Firebase 云功能的数据

问题描述

我正在尝试将我的表单中的数据保存在 Firestore 中。集合用户已经存在,并且文档“电子邮件”也已经存在。它没有保存,也没有给出任何错误或消息。任何想法为什么会发生?我可以从另一个页面保存数据。我复制了相同的 const admin = require('firebase-admin'); 和 const db = admin.firestore();

到这个页面也是如此,完全一样。不工作: let setDoc = db .collection('users') .doc(email) .set({'abc':'def'},{merge: true});
// .set(Encdata,{merge: true}) return setDoc.then(res => { console.log('Set: ', res); }) .catch(error => { console.log(error); });

从另一个页面工作:

     let setA = docRef.set({
       'username': encDec.encrypt(user_name),
       'password' : encDec.encrypt(password),
       'email': email,
       'uid': UserID
     });```


Before and After I trigger the function, data remains the same. All instructions in the function execute fine UNTIL the control reaches the "let setDoc = db" line. After that everything just silently quits.

标签: google-cloud-firestore

解决方案


从您的描述和代码来看,您似乎打算覆盖单个文档。根据 Add data to Cloud Firestore 文档设置一个文档以覆盖单个文档,第一个设置方法适合这种情况。


推荐阅读