https://github.com/eguven/nanomongo
Minimal Python ODM for MongoDB
https://github.com/eguven/nanomongo
database database-design mongodb odm python
Last synced: about 1 year ago
JSON representation
Minimal Python ODM for MongoDB
- Host: GitHub
- URL: https://github.com/eguven/nanomongo
- Owner: eguven
- License: apache-2.0
- Created: 2013-04-04T17:08:23.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2018-04-03T09:28:10.000Z (about 8 years ago)
- Last Synced: 2025-05-08T01:09:25.909Z (about 1 year ago)
- Topics: database, database-design, mongodb, odm, python
- Language: Python
- Size: 152 KB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
=========
nanomongo
=========
.. image:: https://travis-ci.org/eguven/nanomongo.png
:target: https://travis-ci.org/eguven/nanomongo
**nanomongo** is a minimal MongoDB Object-Document Mapper for Python. It does not attempt to be a feature-complete
ODM but if you enjoy using PyMongo_ API with dictionaries and often find yourself writing validators and
``pymongo.Collection`` wrappers, nanomongo might suit your needs.
**Quick Links**: `Source (github) `_ - `Documentation (rtd) `_ - `Packages (PyPi) `_ - `Changelog `_
Quickstart
-----------
::
import pymongo
from nanomongo import Field, BaseDocument
client = pymongo.MongoClient()
# python3 notation, see documentation for python2 options
# we can omit the keyword arguments here and later call MyDoc.register(client=client, db='dbname')
class MyDoc(BaseDocument, dot_notation=True, client=client, db='dbname'):
foo = Field(str)
bar = Field(int, required=False)
__indexes__ = [
pymongo.IndexModel('foo'),
pymongo.IndexModel([('bar', 1), ('foo', -1)], unique=True),
]
doc = MyDoc(foo='L33t') # creates document {'foo': 'L33t'}
doc.insert() # inserts document {'_id': ObjectId('...'), 'foo': 'L33t'}
doc.bar = 42 # records the change
doc.save() # calls collection.update_one {'$set': {'bar': 42}}
MyDoc.find_one({'foo': 'L33t'})
{'_id': ObjectId('...'), 'bar': 42, 'foo': 'L33t'}
:Author: Eren Güven (GitHub_, Twitter_)
:License: `Apache License 2.0 `_
.. _PyMongo: https://api.mongodb.com/python/current
.. _GitHub: https://github.com/eguven
.. _Twitter: https://twitter.com/cyberfart