我的数据库结构
_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)更新属性。
任何人都可以帮忙。 预先感谢。
答案 0 :(得分:0)
我尝试过了。它对我有用
db.myCollection.update({_id:ObjectId("123456789"),authors:{$elemMatch:{authorId:456}}},{$set:{"authors.$.authorname":"prudhvi"}})