![](/img/trans.png)
[英]How to delete an object inside an array, inside an object inside an array with mongodb
[英]How do you push to an array inside of an object, inside of an array with MongoDB?
我需要能够将新对象推送到fameTotals
。 有点麻烦,谢谢!
这是文档在我的数据库中的样子:
{
clanName: null,
clanTag: null,
players: [
{
name: null,
tag: null,
fameTotals: [ //PUSH TO THIS ARRAY
{fame: 0, clanTrophies: 0, date: ''}
]
}
]
}
我一直在尝试使用updateOne()
和$push
运算符来解决这个问题。
检查这个例子
db.collection.update({
_id: 1
},
{
$push: {
players: {
name: "yyy",
tag: "bbbb",
fameTotals: [
{
fame: 1,
clanTrophies: 1,
date: "27-7-21"
}
]
}
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.