I have to do bulk update in Mongodb, for that I am using pymongo.bulk_write method with UpdateOne operations only.
In case of not matched filters I get more fields from other sources and insert the doc. But this is not possible with bulk write, because in return of bulk write I get BulkWriteResult which has following fields
'nInserted': 0
'nMatched': 100
'nModified': 80
'nRemoved': 0
'nUpserted': 0
'upserted': []
'writeConcernErrors': []
'writeErrors': []
Not the matched ids/index.
What will be the optimum way to perform this flow?
(I am using: Mongodb 3.6, python 3.6, pymongo 3.7)
Example:
doc model fields = userid, user_name, last_seen, google_username
On update only last_seen should be updated
db.collection.update( { "user_name": "xyz"},
{ "last_seen": 10000000 })
If user_name not there then insert with all the fields
db.collection.insert({"userid": 1, "user_name": "xyz", "last_seen":10000000, google_username: "xyz@google.com"})
Like that I will have so many user's data.