Skip to content

Commit

Permalink
add how to user client to access mongo. closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelnicolay committed Sep 17, 2012
1 parent 28df577 commit 55925b7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ I am very thankful to asyncmongo, i worked with he in some projects and he's bee

pip install mongotor

## Using
## Using ORM

from mongotor.orm import Collection
from mongotor.orm.field import StringField, ObjectIdField, BooleanField, DateTimeField
Expand Down Expand Up @@ -84,6 +84,29 @@ I am very thankful to asyncmongo, i worked with he in some projects and he's bee
# remove object
yield gen.Task(user_found.remove)

## Using Client

from mongotor.database import Database
from bson import ObjectId

class Handler(tornado.web.RequestHandler):

def initialize(self):
self.db = Database.connect(['localhost:27017','localhost:27018'], 'asyncmongo_test')

@tornado.web.asynchronous
@gen.engine
def get(self):
user = {'_id': ObjectId, 'name': 'User Name'}
yield gen.Task(self.db.user.insert, user)
yield gen.Task(self.db.user.update, user['_id'], {"$set": {'name': 'New User Name'}})

user_found = yield gen.Task(self.db.user.find_one, user['_id'])
assert user_found['name'] == 'New User Name'

yield gen.Task(self.db.user.remove, user['_id'])

## Contributing

Send a pull request (preferred) or patches using ``git format-patch``. Please, write unit and/or functional tests for your new feature.
Expand Down

0 comments on commit 55925b7

Please sign in to comment.