如何在nodejs和mongoose中更新文档内的单个嵌入文档
wpx232ag1#
假设用户集合中有如下文档:
{ _id: "joe", name: "Joe Bookreader", address: { street: "123 Fake Street", city: "Faketon", state: "MA", zip: "12345" } }
您想更新子文档地址吗
var UserModel = require('path-to-user-mongoose-model-here'); UserModel.updateOne({_id:"joe"}, {$set:{ "address.street":"My Updated Street", "address.city":"My City", "address.state":"NY", "address.zip":"11332" } });
1条答案
按热度按时间wpx232ag1#
假设用户集合中有如下文档:
您想更新子文档地址吗