문제

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 including 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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top