MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / save

Method save

mongoengine/document.py:355–495  ·  view source on GitHub ↗

Save the :class:`~mongoengine.Document` to the database. If the document already exists, it will be updated, otherwise it will be created. Returns the saved object instance. :param force_insert: only try to create a new document, don't allow updates of existing d

(
        self,
        force_insert=False,
        validate=True,
        clean=True,
        write_concern=None,
        cascade=None,
        cascade_kwargs=None,
        _refs=None,
        save_condition=None,
        signal_kwargs=None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

353 return True
354
355 def save(
356 self,
357 force_insert=False,
358 validate=True,
359 clean=True,
360 write_concern=None,
361 cascade=None,
362 cascade_kwargs=None,
363 _refs=None,
364 save_condition=None,
365 signal_kwargs=None,
366 **kwargs,
367 ):
368 """Save the :class:`~mongoengine.Document` to the database. If the
369 document already exists, it will be updated, otherwise it will be
370 created. Returns the saved object instance.
371
372 :param force_insert: only try to create a new document, don't allow
373 updates of existing documents.
374 :param validate: validates the document; set to ``False`` to skip.
375 :param clean: call the document clean method, requires `validate` to be
376 True.
377 :param write_concern: Extra keyword arguments are passed down to
378 :meth:`~pymongo.collection.Collection.save` OR
379 :meth:`~pymongo.collection.Collection.insert`
380 which will be used as options for the resultant
381 ``getLastError`` command. For example,
382 ``save(..., write_concern={w: 2, fsync: True}, ...)`` will
383 wait until at least two servers have recorded the write and
384 will force an fsync on the primary server.
385 :param cascade: Sets the flag for cascading saves. You can set a
386 default by setting "cascade" in the document __meta__
387 :param cascade_kwargs: (optional) kwargs dictionary to be passed throw
388 to cascading saves. Implies ``cascade=True``.
389 :param _refs: A list of processed references used in cascading saves
390 :param save_condition: only perform save if matching record in db
391 satisfies condition(s) (e.g. version number).
392 Raises :class:`OperationError` if the conditions are not satisfied
393 :param signal_kwargs: (optional) kwargs dictionary to be passed to
394 the signal calls.
395
396 .. versionchanged:: 0.5
397 In existing documents it only saves changed fields using
398 set / unset. Saves are cascaded and any
399 :class:`~bson.dbref.DBRef` objects that have changes are
400 saved as well.
401 .. versionchanged:: 0.6
402 Added cascading saves
403 .. versionchanged:: 0.8
404 Cascade saves are optional and default to False. If you want
405 fine grain control then you can turn off using document
406 meta['cascade'] = True. Also you can pass different kwargs to
407 the cascade save using cascade_kwargs which overwrites the
408 existing kwargs with custom values.
409 .. versionchanged:: 0.26
410 save() no longer calls :meth:`~mongoengine.Document.ensure_indexes`
411 unless ``meta['auto_create_index_on_save']`` is set to True.
412

Callers 9

putMethod · 0.45
_put_thumbnailMethod · 0.45
cascade_saveMethod · 0.45
tumblelog.pyFile · 0.45
save_bookFunction · 0.45
create_and_delete_bookFunction · 0.45
test_big_docFunction · 0.45
save_companyFunction · 0.45

Calls 14

to_mongoMethod · 0.95
_get_collectionMethod · 0.95
ensure_indexesMethod · 0.95
_save_createMethod · 0.95
_save_updateMethod · 0.95
cascade_saveMethod · 0.95
NotUniqueErrorClass · 0.85
OperationErrorClass · 0.85
_clear_changed_fieldsMethod · 0.80
getMethod · 0.45
validateMethod · 0.45

Tested by 5

save_bookFunction · 0.36
create_and_delete_bookFunction · 0.36
test_big_docFunction · 0.36
save_companyFunction · 0.36