nanomongo.document¶
-
class
nanomongo.document.BaseDocument(*args, **kwargs)[source]¶ BaseDocument class. Subclasses should be used. See
__init__()-
add_to_set(field, value)[source]¶ Explicitly defined
$addToSetfunctionality. This sets/updates the field value accordingly and records the change to be saved withsave().# MongoDB style dot notation can be used to add to lists # in embedded documents doc = Doc(foo=[], bar={}) doc.add_to_set('foo', new_value)
Contrary to how
$seting the same value has no effect under __setitem__ (see.util.RecordingDict.__setitem__()) when the new value is equal to the current, this explicitly records the change so it will be sent to the database whensave()is called.
-
classmethod
find_one(*args, **kwargs)[source]¶ pymongo.Collection().find_onewrapper for this document
-
get_dbref()[source]¶ Return a
bson.DBRefinstance for thisBaseDocumentinstance
-
insert(**kwargs)[source]¶ Runs auto updates, validates the document, and inserts into database. Returns
pymongo.results.InsertOneResult.
-
classmethod
register(client=None, db=None, collection=None)[source]¶ Register this document. Sets client, database, collection information, creates indexes and sets SON manipulator
-
save(**kwargs)[source]¶ Runs auto updates, validates the document, and saves the changes into database. Returns
pymongo.results.UpdateResult.
-
validate()[source]¶ Override this to add extra document validation. It will be called during
insert()andsave()before the database operation.
-