简体   繁体   中英

How to update a nested field in firestore using node.js?

How to update the child in firestore using node.js? Here is my data:

{  firstName : "youg",
   id: 9,
   lastName : "Nue",
   room : {
     floor : 14,
     no : 103  
     temp : 50
  }
}

I tried update, but failed:

const studentId = '1tqfC07qO8zrVApOYVSU';
await db.collection('students').doc(studentId).update( {
    'room\floor'  : '12'
    }
);  

Thank You.

To update a nested field you need to use a . in its name. So:

db.collection('students').doc(studentId).update({
  'room.floor'  : '12'
});  

Also see the documentation on updating fields in a nested object .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM