我尝试做的很简单,我在文档中有一个数组 ;
"tags": [
{
"t" : "architecture",
"n" : 12
},
{
"t" : "contemporary",
"n" : 2
},
{
"t" : "creative",
"n" : 1
},
{
"t" : "concrete",
"n" : 3
}
]
Run Code Online (Sandbox Code Playgroud)
我想将一个项目数组推送到数组
["architecture","blabladontexist"]
Run Code Online (Sandbox Code Playgroud)
如果item存在,我想增加对象的n值(在这种情况下是它architecture),
如果不这样做,请将其添加为新项目(值为n=0){ "t": "blabladontexist", "n":0}
我已经试过$addToSet,$set,$inc,$upsert: true有这么多的组合,不能做到这一点.
我们怎样才能在MongoDB中做到这一点?
mongodb ×1