[英]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.