Skip to content

Commit 05b55e8

Browse files
authored
PYTHON-3038 The doc should clarify that the resulting documents that are produced with upserts are constructed from both the filter and the update params (#933)
1 parent 9e317bf commit 05b55e8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pymongo/collection.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,19 @@ def update_one(
952952
{'x': 1, '_id': 1}
953953
{'x': 1, '_id': 2}
954954
955+
If ``upsert=True`` and no documents match the filter, create a
956+
new document based on the filter criteria and update modifications.
957+
958+
>>> result = db.test.update_one({'x': -10}, {'$inc': {'x': 3}}, upsert=True)
959+
>>> result.matched_count
960+
0
961+
>>> result.modified_count
962+
0
963+
>>> result.upserted_id
964+
ObjectId('626a678eeaa80587d4bb3fb7')
965+
>>> db.test.find_one(result.upserted_id)
966+
{'_id': ObjectId('626a678eeaa80587d4bb3fb7'), 'x': -7}
967+
955968
:Parameters:
956969
- `filter`: A query that matches the document to update.
957970
- `update`: The modifications to apply.

0 commit comments

Comments
 (0)