SoFunction
Updated on 2024-11-17

python mongo add data operations to array types in data

I'll cut to the chase, let's just go straight to the pictures~

Additional knowledge:The use of pymongo to update and not update when inserting data

(1) setOnInsert of update

Performs an insert operation when the key does not exist, but does not care when it does, using setOnInsert.

({'_id': 'id'}, {'$setOnInsert': {'a': 'a'}, true)

Ignore setOnInsert when the id exists.

(2) set of update

Performs an insert operation when the key does not exist, and updates the values in the set other than the key when it does exist.

({'_id': 'id'}, {'$set': {'b': 'b'}}, true)

When the id exists, to insert it, insert {'a': 'a'}

The final argument, true, specifies that the insert operation is performed when updating a non-existent _id. The default is false, which only updates, not inserts.

(3)insert

insert is to insert the content directly into the database, which will result in duplicate insertion of data.

The above this python mongo to the data in the array type of new data operation is all I share with you, I hope to give you a reference, and I hope you support me more.