Thursday, 15 May 2014

bulkinsert - MongoDB Bulk Silent Update -


I need to put a set of documents in the remote MongoDB example, in which some of these documents may already be in the frequency That is, if _id is the parameter I want Mongoediabi to ignore such documents and commit the rest.

The default behavior of PyMongo's insert method is that it returns the duplicate arrow exception for each duplicate document that arrives on the remote server. I want to suppress this behavior in more fire and forget about efficiency.

If someone knows how to do this it would be commendable.

For bulk inserts, where duplicate key errors can occur you have continue_on_error < / P>

This flag will continue with inserts even if there is an error. The last error will be reported back by getLastError - which you can catch or if you want a fire and forget set to 0.

pymongo import * client = from MongoClient

  () Coll = client.test.test coll.drop () # Add a test document coll.save ({'_ id': 1 , 'Hello': 'world'}) print (coll.count ()) #inless flag - boom coll.insert ({{"_ id": 1, "hello": "world"}, {"_id": 2, "Howdy": "Worldy"}] print (coll.count ()) with a concern of # 0 - no errors, but not saved Coll.insert (["_ id": 1, "Hello ":" World "}, {" _id ": 2," howdy ":" worldy "}], w = 0 print (coll.count ()) will be # error but coll.insert ([[" _ id ": 1," Hello ":" world "}, {" _id ": 2," howdy ":" worldy "}], continue_interval = true will print (coll.c Writing a concern of 0 with a continuing operation and 0 - If only some socket or network error is coll.insert ([{"{_}", "hello": "world"}, {"_id" (2) "Howdy": "Worldy"}, {"_id": 3, "Hi": "world"}], w = 0, continue_on_error = true Print (coll.count ())  / Pre>  

No comments:

Post a Comment