我必须通过查询用户ID是否在数组中来运行mongo更新。是否可以插入不在数组中的任何值?
例如:
db.collection.update({
userId:{
$in:['1','2', '3']
}
},
{$set: {score:30}},
{upsert:true})
如果我运行此查询,我会获得一个带有_id和得分的新文档。我想要做的是为userId数组中没有的每个userId提供一个新文档:
[{userId:1, score:30, _id:...}, {userId:2, score: 30, _id: ...}, ...]
mongo有可能吗?