Firestore更新单个字段但创建另一个节点

时间:2017-12-26 07:50:26

标签: javascript firebase react-native google-cloud-firestore

我正在更新单个字段名称,即“name”,我成功编辑它,但它创建了另一个节点。像这样I only want it to be Name: "Christian" not Name: "Name": "Christian"

这是我的代码:

const user = firebase.auth().currentUser;
    let uid;
    if (user != null) {
      uid = user.uid;
      const db = firebase.firestore();
      const docRef = db.collection('users').doc(uid);
      docRef.update({
        name,
        timestamp: firebase.firestore.FieldValue.serverTimestamp()
      }).then(() => {
        console.log('Profile Successfully Edited!');
      }).catch((error) => {
        console.log('Error updating the document:', error);
      })
    }

2 个答案:

答案 0 :(得分:2)

我已经找到了解决方案,

if (user != null) {
      uid = user.uid;
      const db = firebase.firestore();
      db.collection('users').doc(uid).update({
        name })....

我只是直接将.update放到db引用中。

答案 1 :(得分:0)

尝试

.active{
color: green;
}

您可以在<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="contacts"> <ul> </ul> </div>

之后传递字符串var