Answer the question
In order to leave comments, you need to log in
Where can I find a working tornado motor sample?
Experimenting with tornado as an asynchronous mongo driver trying to use motor. My code:
class Application(tornado.web.Application):
def __init__(self):
db_name = config['database']['name']
self.db = motor.MotorClient(config['database']['host'], config['database']['port'])[db_name]
settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=True,
autoescape=None
)
tornado.web.Application.__init__(self, url_patterns, **settings)
class MainHandler(tornado.web.RequestHandler):
def get(self):
doc={'who': 'data who'}
self.application.db.insert(doc, callback=self.some_function)
Answer the question
In order to leave comments, you need to log in
Everything turned out to be simple - you need to insert values into the collection, but it was inserted into the
self.application.db database. chat_messages .insert(doc, callback=self.some_function)
class MainHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
doc={'who': 'data who'}
self.application.db.insert(doc, callback=self.some_function)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question