Skip to content

bcoe/mongate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()

About

Client for Sleepy Mongoose that provides the same interface as Pymongo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages