【发布时间】:2019-01-09 15:52:44
【问题描述】:
我的数据库结构
_id:ObjectId("123456789")
name:"prudhvi"
authors:Array
0:Object
authorId:123
authorname:"venkat"
department:software
1:Object
authorId:456
authorname:"venkat"
department:hardware
我的数据库结构是这样的。我需要更新1:Object,我正在尝试根据 authorId 和 userid(_id) 更新属性
谁能帮忙。 提前致谢。
【问题讨论】:
-
你用的是mongodb还是mongoose?
-
请贴出您尝试过的代码。你使用的是 mongodb 还是 mongoose?
-
我正在使用猫鼬。我试过这个。但它正在更新 authorId -----> db.myCollection.update({_id:ObjectId("123456789")},{$set:{"authors":[{authorId:456},{authorname:"dublin" }]}})
-
我在这里传递 (_id) 但我不知道如何传递 authorId。