开发者

Removing multiple MongoDB documents in Python

Greetings,

I am attempting to remove multiple documents from a MongoDB collection using the following syntax. I don't know if this is correct as I found it somewhere on the internet and haven't been able to find anything since enforcing the legitimacy of this statement:

pymongo_collection_object.remove(
    [
        {
            'sku': '100-00'
        },
        {
            'sku': '200-00'
        }
    ]
, safe=True)

I would expect the above code would remove both documents inclu开发者_开发百科ding a 'sku' value of '100-00' or '200-00' but unfortunately both documents are still present within the collection. I also tried casting both the 'sku' key and its value to Unicode as I know they are stored in this encoding. As you can tell I am also enabling safe mode ensuring that there is nothing out of line happening on the server side.

Any help is appreciated, thank you!


You can do so by using $or / $in operators.

Try this:

pymongo_collection_object.remove({'$or': [{'sku': '100-00'}, {'sku': '200-00'}]}, safe=True)

or

pymongo_collection_object.remove({'sku': {'$in': ['100-00', '200-00']}}, safe=True)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜