Client for Sleepy Mongoose that provides the same interface as Pymongo
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
mongate
tests
.gitignore
README.textile
setup.cfg
setup.py

README.textile

Mongate

A client library for Sleepy Mongoose that provides the same interface as Pymongo.

Usage

Connect to Sleepy Mongoose

connection = Connection(SLEEPY_HOST, SLEEPY_PORT)
connection.connect_to_mongo(host=MONGO_HOST, port=MONGO_PORT)

Select a Database and Collection

db = connection.db_name
collection = db.collection_name

Insert Data

collection.save({’key’: ’value’})

Retrieve Data

collection.find({’key’: ’value’})

or

collection.find_one({’key’: ’value’})

Count Data

collection.count({’key’: ’value’})

Update Data

collection.update({’key’: ’value’}, {’$set’: {’key’: ’value’}})

or use save() with an object that has already been loaded.

HTTPS/Basic Auth

Mongate supports HTTPS and Basic-Auth. just set auth and https to True when instantiating a Connection.

Batch Operations

I’ve implemented an object with a similar API for performing batch operations in Mongate this should make real-world applications more practical.

Batch operations supported: insert, update, remove, find. They all work similar to the following (see unit tests for more details):

batch = Batch(self.collection, self.connection)

batch.add_update({’batch_insert_1’: 3}, {"$inc": {"bar": 1}})

batch.add_update(‘batch_insert_2’: ’banana’}, {’$set’: {’banana’: ’tasty’}})

batch.execute()