Bulk update in Pymongo using multiple ObjectId

前端 未结 2 749
暖寄归人
暖寄归人 2020-12-17 01:28

I want to update thousands of documents in mongo collection. I want to find them using ObjectId and then whichever document matches , should be updated. My update is same fo

2条回答
  •  星月不相逢
    2020-12-17 02:08

    I got the answer, It can be done like this :

        bulk = db.testdata.initialize_unordered_bulk_op()
        for i in range (0, len(ids)):
            bulk.find( { '_id':  ids[i]}).update({ '$set': {  "isBad" : "N" }})
        print bulk.execute()
    

提交回复
热议问题