MongoDB backend
A storage/query backend for MongoDB.
Warning
this module is not intended for production, it’s just a (working)
example. Patches, improvements, rewrites are welcome.
-
class pymodels.backends.mongodb.Storage(host='127.0.0.1', port=27017, database='default', collection='default')
-
get(model, primary_key)
- Returns model instance for given model and primary key.
Raises KeyError if there is no item with given key in the database.
-
save(model, data, primary_key=None)
Saves given model instance into the storage. Returns primary key.
Parameters: |
- model – model class
- data – dict containing all properties to be saved
- primary_key – the key for given object; if undefined, will be
generated
|
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.
-
class pymodels.backends.mongodb.Query(storage, model)
-
delete()
- Deletes all records that match current query.
-
where(**conditions)
- 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.