我有一个文件
{
_id: "5dc543bbc74700da0428e5cc",name: "groupDef",groups: [
{id:"group-00",label:"group 00"},{id:"group-01",label:"group 01"},{id:"group-102",label:"group 102"}
]
}
,如果不存在,我想再推group
。所以我写下面的更新命令
db.data.update(
{
'name': 'groupDef',},{
$push: {
'groups': {
$cond: {
if: { $not: { $in: ["group-02","$groups.id"] } },then: {
id: "group-02",label: "gorup 02",else: null
}
}
}
}
)
失败,并显示消息"errmsg" : "The dollar ($) prefixed field '$cond' in 'groups..$cond' is not valid for storage."
。您能帮我理解应该怎么写。