Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,假设我有这个文件 {name : "John", Address : { Street : "Main St", City : "Houston", State : "TX"}, email : "John@gmail.com"}
如果我想删除上述文档中的子文档“Street”,我该怎么办?如果我想添加一个子文档“Zip”。
db.collection.remove()
顺便说一句, db.collection.find() 中是否有任何通配符来匹配字段名称?
您正在寻找$set和$unset。你会像这样使用它:
$set
$unset
db.collection.update({name: "John"}, {$unset: {"address.street": ""}, $set: {"address.zip": 94105}})
MongoDB 中没有通配符字段名称匹配器。我预计未来不会有一个。