Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Mongo-使用$pull删除数组元素不使用$nin(不存在)_Arrays_Mongodb - Fatal编程技术网

Arrays Mongo-使用$pull删除数组元素不使用$nin(不存在)

Arrays Mongo-使用$pull删除数组元素不使用$nin(不存在),arrays,mongodb,Arrays,Mongodb,我有下面的查询,它可以与$in一起使用,但不能与$nin一起使用。 我正在尝试从所有记录中按名称删除链接列表项(itemA和itemB),这些记录不是包含“@NOT\u this”或“@nor\u this”用户名的文档的一部分 db.users.update({userName:{$nin: [ RegExp('@not_these.com'), RegExp('@nor_these.com') ]}},{$pull:{'myLinkList': {name: {$in: ['itemA',

我有下面的查询,它可以与$in一起使用,但不能与$nin一起使用。 我正在尝试从所有记录中按名称删除链接列表项(itemA和itemB),这些记录不是包含“@NOT\u this”或“@nor\u this”用户名的文档的一部分

db.users.update({userName:{$nin: [ RegExp('@not_these.com'), RegExp('@nor_these.com') ]}},{$pull:{'myLinkList': {name: {$in: ['itemA', 'itemB']} } } } )  
如果我将其设为$in并显式声明RegExp(),它确实会按预期删除数组项

db.users.update({userName:{$in: [ RegExp('@yes_these.com'), RegExp('@and_these.com') ]}},{$pull:{'myLinkList': {name: {$in: ['itemA', 'itemB']} } } } ) 
对于那些显式声明的用户,这个函数确实会删除itemA和itemB数组列表项。 为什么不能使用第一个示例删除项目“@yes\u this”和“@and\u this”?它在执行时似乎什么也做不了

样本文件:

{
"_id": ObjectId('5e34741aa18d8a0c24078b61'),
"myLinkList": [
    {
        "name": "item",
        "created": ISODate('2020-01-31T18:38:18.682Z'),
        "managedBy": [
            "imm"
        ]
    },
    {
        "name": "itemA",
        "created": ISODate('2020-01-31T18:38:18.682Z'),
        "managedBy": [
            "imm"
        ]
    },
    {
        "name": "itemB",
        "created": ISODate('2020-01-31T18:38:18.682Z'),
        "managedBy": [
            "imm"
        ]
    }
],
"userName": "@yes_these.com"
}
更新后(希望如此):


我验证了这一点:

db.users.updateMany({userName:{$nin: [ /@not_these\.com/), /@nor_these\.com/) ]}},{$pull:{'myLinkList': {name: {$in: ['itemA', 'itemB']} } } } )

是否有包含before/after数据的示例文档?是添加的示例after将不包含最后两个myLinkList项。这是使用MongoDB shell版本:2.0.4
db.users.updateMany({userName:{$nin: [ /@not_these\.com/), /@nor_these\.com/) ]}},{$pull:{'myLinkList': {name: {$in: ['itemA', 'itemB']} } } } )