Update fields in nested objects in firestore documents?

前端 未结 1 1629
庸人自扰
庸人自扰 2020-11-29 09:08

I have a data structure like:

I want to edit the value of \"test\" key in \"first\" object. I followed the document on https://firebase.google.com/docs/fire

相关标签:
1条回答
  • 2020-11-29 09:58

    According to the link you provided, it says this:

    If your document contains nested objects, you can use "dot notation" to reference nested fields within the document when you call update():

    Therefore you need to use dot notation to be able to update only one field without overwriting, so like this:

    var setAda = dbFirestore.collection('users').doc('alovelace').update({
        "first.test": "12345"
    });
    

    then you will have:

     first
      test: "12345"
      test2: "abcd"
    
    0 讨论(0)
提交回复
热议问题