Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (29 sloc) 1.38 KB


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


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{’key’: ’value’})

Retrieve Data

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


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’}})