Skip to content

Commit 043bb9a

Browse files
committed
Clarify use of manipulate in save PYTHON-200
Also clarified the use of manipulate in insert.
1 parent 879c0ee commit 043bb9a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

pymongo/collection.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ def save(self, to_save, manipulate=True, safe=False, **kwargs):
170170
171171
If `to_save` already has an ``"_id"`` then an :meth:`update`
172172
(upsert) operation is performed and any existing document with
173-
that ``"_id"`` is overwritten. Otherwise an ``"_id"`` will be
174-
added to `to_save` and an :meth:`insert` operation is
175-
performed. Returns the ``"_id"`` of the saved document.
173+
that ``"_id"`` is overwritten. Otherwise an :meth:`insert`
174+
operation is performed. In this case if `manipulate` is ``True``
175+
an ``"_id"`` will be added to `to_save` and this method returns
176+
the ``"_id"`` of the saved document. If `manipulate` is ``False``
177+
the ``"_id"`` will be added by the server but this method will
178+
return ``None``.
176179
177180
Raises :class:`TypeError` if `to_save` is not an instance of
178181
:class:`dict`. If `safe` is ``True`` then the save will be
@@ -215,13 +218,15 @@ def insert(self, doc_or_docs,
215218
manipulate=True, safe=False, check_keys=True, **kwargs):
216219
"""Insert a document(s) into this collection.
217220
218-
If `manipulate` is set, the document(s) are manipulated using
221+
If `manipulate` is ``True``, the document(s) are manipulated using
219222
any :class:`~pymongo.son_manipulator.SONManipulator` instances
220-
that have been added to this
221-
:class:`~pymongo.database.Database`. Returns the ``"_id"`` of
222-
the inserted document or a list of ``"_id"`` values of the
223-
inserted documents. If the document(s) does not already
224-
contain an ``"_id"`` one will be added.
223+
that have been added to this :class:`~pymongo.database.Database`.
224+
In this case an ``"_id"`` will be added if the document(s) does
225+
not already contain one and the ``"id"`` (or list of ``"_id"``
226+
values for more than one document) will be returned.
227+
If `manipulate` is ``False`` and the document(s) does not include
228+
an ``"_id"`` one will be added by the server. The server
229+
does not return the ``"_id"`` it created so ``None`` is returned.
225230
226231
If `safe` is ``True`` then the insert will be checked for
227232
errors, raising :class:`~pymongo.errors.OperationFailure` if

0 commit comments

Comments
 (0)