A storage/query backend for MongoDB.
status: | beta |
---|---|
database: | MongoDB |
dependencies: | pymongo |
suitable for: | general purpose (mostly server-side) |
Warning
this module is not intended for production. It contains some hacks and should be refactored. However, it is actually used in a real project involving complex queries. Patches, improvements, rewrites are welcome.
Parameters: |
|
---|
Clears the whole storage from data.
Permanently deletes the record with given primary key from the database.
Returns model instance for given model and primary key. Raises KeyError if there is no item with given key in the database.
Returns a list of documents with primary keys from given list. More efficient than calling get() multiple times.
Queries the database for records associated with given document class and conforming to given extra condtions. If such records exist, picks the first one (the order may be random depending on the database). If there are no such records, creates one.
Returns the document instance and a boolean value “created”.
Gracefully closes current connection (if it’s not broken) and connects again to the database (e.g. reopens the file).
Saves given model instance into the storage. Returns primary key.
Parameters: |
|
---|
Note that you must provide current primary key for a model instance which is already in the database in order to update it instead of copying it.
Deletes all records that match current query.
Returns distinct values for given field.
Parameters: |
|
---|
Note
A set is dynamically build on client side if the query contains conditions. If it doesn’t, a much more efficient approach is used. It is only available within current connection, not query.
Returns Query instance filtered by given conditions. The conditions are defined exactly as in Pyrant’s high-level query API. See pyrant.query.Query.filter documentation for details.
Returns Query instance. Inverted version of where().