pymongo 根据 _id删除documents

删除单条数据:

db.user.remove(spec_or_id={"_id":ObjectId('5050457a1308122ec272d24c')},safe=True)

注意在这之前一定要导入ObjectId类:

from bson.objectid import ObjectId

删除多条数据:

db.user.remove({"_id":{"$in":[ObjectId('505905dd13081207bef3a0f3'),ObjectId('505905e413081207c410c161')]}},safe=True)

也可以是:

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

你可能感兴趣的:(pymongo 根据 _id删除documents)