Documents by themselves does not have ability to save to database. To do that you should use a collection object. Its easy to use collections by subclassing the Collection base class.
See also
Since :py:class: ~djamo.collections.BaseCollection is a subclass of PyMongos Collection class, and we don’t document the methods that does not overridden, it will be heplful for you to take a look at PyMongo Collection document too.
This collection class is the base of other Djamo collections and contains the same interface as PyMongo.
Djamo implementation of Mongodb collection.
This class contains all the handlers of query specific operator of MongoDB.
Handle the $bit operator for document update.
Handle the $pop operator for document update.
Check the collection’s document and return it if it was a valid document
validate doc_or_docs and create a dictionary data.
Prepare each query_item (key, value) for the specific query type.
Class that will be use as a document class for this collection. This class will be responsible for pickling and unpickling data to and from database.
alias of dict
make queries on database and current collection.
The spec argument is a prototype document that all results must match. For example:
from .models import UserBaseCollection
collection = UserBaseCollection() collection.find({“username”: “Okarin”})
only matches documents that have a key “username” with value “Okarin”. Matches can have other keys in addition to “Okarin. The fields argument is used to specify a subset of fields that should be included in the result documents. By limiting results to a certain subset of fields you can cut down on network traffic and decoding time.
Parameters: |
|
---|---|
Pram fields: | (optional) a list of field names that should be returned in the result set or a dict specifying the fields to include or exclude. If fields is a list _id will always be returned. Use a dict to exclude fields from the result (e.g. fields={_id: False}). |
Get a single document from the database. All arguments to find() are also valid arguments for find_one(), although any limit argument will be ignored. Returns a single document, or None if no matching document is found.
Parameters: | spec_or_id – (optional) a dictionary specifying the query to be performed OR any other type to be used as the value for a query for “_id”. |
---|
Index list for current collection, each element will be a index dictionary according to mongodb standards. Each element should be a list with index dictionary as its first element and index options as its second.
Insert a document(s) into current collection. and return the _id value (or list of _id values) of doc_or_docs or [None] if manipulate is False and the documents passed as doc_or_docs do not include an _id field.
Parameters: |
|
---|
Specify the name of collection in database level. In case of a None value current collection class name will use in lower case
Prepare query (spec).
Remove a document(s) from this collection. returns A document (dict) describing the effect of the remove or None if write acknowledgement is disabled.
If spec_or_id is None, all documents in this collection will be removed This is not equivalent to calling drop_collection(), however, as indexes will not be removed.
By default an acknowledgment is requested from the server that the remove was successful, raising OperationFailure if an error occurred. Passing w=0 disables write acknowledgement and all other write concern options.
Parameters: |
|
---|
save a document(s) into current collection. and return the _id value (or list of _id values) of doc_or_docs or [None] if manipulate is False and the documents passed as doc_or_docs do not include an _id field.
Parameters: |
|
---|
Update a document(s) in this collection.
Parameters: |
|
---|
Return a validated instance of the current collection document from provided doc parameter.
Parameters: | doc – An instance of the current collection document or a dictionary like object. |
---|
This class is contains all the methods that are wrappers to PyMongo interface or PyMongo did not provided.
Update all the documents which matched to spec.
Parameters: |
|
---|