MODELS for MONGODB


License
BSD-1-Clause
Install
pip install mondb==0.0.5.2

Documentation

#MDB- MongoDB Models

Build Status PyPI version PyPI Code Health

##Installation

You can install mondb from its official pypi repository.

 pip install mondb

##Models Inorder to create a Model you first need to inherit Document class in Mondb

from mondb.Connection import create_engine
import mondb


#used to establish a connection with the collection
create_engine(database ="Management", host= "localhost", port=27017)


class User(mdb.Document):
    name = mondb.StringProperty()
    age = mondb.IntegerProperty()

m = User(name = "sathya", age =23)
m.save()

##Searching and Updating

In most of the case where the user needs to search and update models. Mondb comes with methods such as search() and find() for finding a document from the collection.

#search returns a matching records as pymongo cursor.
cursor = User.search(name="sathya")

# Note:
#    cursor is not a list but can be indexed. use list(cursor) if you want to use
#    it as a list

for record in cursor:
    print record

##Query

Mondb also comes with a Query object where you can Query with some criteria.

query = mondb.Query(User)

query.filter("age", ">=", 20)

lst = query.fetch()

for l in lst:
    print l

Methods such as filter() and fetch() will be handy for getting results from the query.

##Deleting

Mondb models can be deleted with the help of delete() method.

user = User.search(age=23)[0]
user.delete()

##License

MIT

Bitdeli Badge