skip to Main Content

Mongodb – Updating and Adding on multiple documents using pymongo

I have a mongo database having data record like below [ {"name" : "a", "email" : "[email protected]","ml_pred":"valid","hum_pred":"null", "score":0.92}, {"name" : "b","email" : "[email protected]","ml_pred":"invalid","hum_pred":"null", "score":0.2}, {"name" : "c","email" : "[email protected]","ml_pred":"null","hum_pred":"null"}, {"name" : "d","email" : "[email protected]","ml_pred":"null","hum_pred":"null"}, {"name" : "e","email" : "[email protected]","ml_pred":"null","hum_pred":"null"} ]…

VIEW QUESTION

Mongodb – Pymongo how to set read_preference

How do we enable PyMongo to read from the nearest? This field db.read_preference is read-only now. from pymongo import ReplicaSetConnection from pymongo import ReadPreference db = ReplicaSetConnection('localhost:27017', replicaSet='rs1')['my_db'] db.read_preference = ReadPreference.NEAREST db.tag_sets = [{'secondaries': 1}]

VIEW QUESTION

MongoDB: Upsert with array filter

I have collection like this: mc.db.collection.insert_many([ {"key_array": [1], "another_array": ["a"]}, {"key_array": [2, 3], "another_array": ["b"]}, {"key_array": [4], "another_array": ["c", "d"]}, ]) And I'm using this kind of updates: mc.db.collection.update_one( {"key_array": 5}, {"$addToSet": {"another_array": "f"}}, upsert=True ) It works good with…

VIEW QUESTION
Back To Top
Search