【发布时间】:2017-10-18 05:44:41
【问题描述】:
我必须通过查询用户 ID 在数组中来运行 mongo 更新。是否可以插入任何不在数组中的值?
例如:
db.collection.update({
userId:{
$in:['1','2', '3']
}
},
{$set: {score:30}},
{upsert:true})
如果我运行这个查询,我会得到一个带有 _id 和 score 的新文档。我想做的是为 userId 数组中不存在的每个 userId 创建一个新文档:
[{userId:1, score:30, _id:...}, {userId:2, score: 30, _id: ...}, ...]
这在 mongo 中可行吗?
【问题讨论】:
标签: mongodb