A single instance of MongoDB can support multiple independent
databases. From an open connection, you can get a reference to a
particular database with dot-notation or bracket-notation:
>>> db = connection.test_database
>>> db = connection['test_database']
the second one (connection['name_of_the_database']) is used when the
name of database dont respects python variable naming.
On 6 oct, 22:59, "A. Jesse Jiryu Davis" <ajesseda...@gmail.com> wrote:
am sorry for asking this dumb question, but can i use this technique
(which is used in the examples of projects made by tornado users) to
make inheritence?
class BaseHandler(tornado.web.RequestHandler):
def get_current_user(self):
user = self.get_secure_cookie("current_user") or False
if not user: return None
return tornado.escape.json_decode(user)
@property
def db(self):
if not hasattr(BaseHandler,"_db"):
_db = pymongo.Connection().tuxhub
return _db
@property
def fs(self):
if not hasattr(BaseHandler,"_fs"):
_fs = gridfs.GridFS(self.db)
return _fs
it will work in the same maneer in Motor? because i've seen a
parameter:
No, because your properties are accessed synchronously.
So, this line:
_fs = gridfs.GridFS(self.db)
... opens a GridFS object in a *blocking* style. The next line isn't executed until the object has been created. The IOLoop is blocked and no more requests can be processed until the GridFS object is created. In Motor, on the other hand, you need to open it asynchronously:
On the other hand, if you look at the code for the regular PyMongo gridfs.GridFS constructor, you'll see all it does is an ensure_index(), which (assuming the index is already created) is so fast that it's probably not a problem. *Reading* from a PyMongo GridFS object, however, will block the IOLoop until complete, which for large files *will* be a problem.
On Saturday, October 6, 2012 3:27:01 PM UTC-7, aliane abdelouahab wrote:
> am sorry for asking this dumb question, but can i use this technique > (which is used in the examples of projects made by tornado users) to > make inheritence?
> class BaseHandler(tornado.web.RequestHandler): > def get_current_user(self): > user = self.get_secure_cookie("current_user") or False > if not user: return None > return tornado.escape.json_decode(user)
> @property > def db(self): > if not hasattr(BaseHandler,"_db"): > _db = pymongo.Connection().tuxhub > return _db
> @property > def fs(self): > if not hasattr(BaseHandler,"_fs"): > _fs = gridfs.GridFS(self.db) > return _fs
> it will work in the same maneer in Motor? because i've seen a > parameter:
> No, because your properties are accessed synchronously.
> So, this line:
> _fs = gridfs.GridFS(self.db)
> ... opens a GridFS object in a *blocking* style. The next line isn't
> executed until the object has been created. The IOLoop is blocked and no
> more requests can be processed until the GridFS object is created. In
> Motor, on the other hand, you need to open it asynchronously:
> On the other hand, if you look at the code for the regular PyMongo
> gridfs.GridFS constructor, you'll see all it does is an ensure_index(),
> which (assuming the index is already created) is so fast that it's probably
> not a problem. *Reading* from a PyMongo GridFS object, however, will block
> the IOLoop until complete, which for large files *will* be a problem.
> On Saturday, October 6, 2012 3:27:01 PM UTC-7, aliane abdelouahab wrote:
> > am sorry for asking this dumb question, but can i use this technique
> > (which is used in the examples of projects made by tornado users) to
> > make inheritence?
> > class BaseHandler(tornado.web.RequestHandler):
> > def get_current_user(self):
> > user = self.get_secure_cookie("current_user") or False
> > if not user: return None
> > return tornado.escape.json_decode(user)
> so i'll avoid the classic way to make gridfs and pymongo inherit and
> declare them in each class?
> On 7 oct, 05:07, "A. Jesse Jiryu Davis" <ajesseda...@gmail.com> wrote:
> > No, because your properties are accessed synchronously.
> > So, this line:
> > _fs = gridfs.GridFS(self.db)
> > ... opens a GridFS object in a *blocking* style. The next line isn't
> > executed until the object has been created. The IOLoop is blocked and no
> > more requests can be processed until the GridFS object is created. In
> > Motor, on the other hand, you need to open it asynchronously:
> > On the other hand, if you look at the code for the regular PyMongo
> > gridfs.GridFS constructor, you'll see all it does is an ensure_index(),
> > which (assuming the index is already created) is so fast that it's
> probably
> > not a problem. *Reading* from a PyMongo GridFS object, however, will
> block
> > the IOLoop until complete, which for large files *will* be a problem.
> > On Saturday, October 6, 2012 3:27:01 PM UTC-7, aliane abdelouahab wrote:
> > > am sorry for asking this dumb question, but can i use this technique
> > > (which is used in the examples of projects made by tornado users) to
> > > make inheritence?
> > > class BaseHandler(tornado.web.RequestHandler):
> > > def get_current_user(self):
> > > user = self.get_secure_cookie("current_user") or False
> > > if not user: return None
> > > return tornado.escape.json_decode(user)
> On Sun, Oct 7, 2012 at 1:18 AM, aliane abdelouahab
> <alabdeloua...@gmail.com>wrote:
> > so i'll avoid the classic way to make gridfs and pymongo inherit and
> > declare them in each class?
> > On 7 oct, 05:07, "A. Jesse Jiryu Davis" <ajesseda...@gmail.com> wrote:
> > > No, because your properties are accessed synchronously.
> > > So, this line:
> > > _fs = gridfs.GridFS(self.db)
> > > ... opens a GridFS object in a *blocking* style. The next line isn't
> > > executed until the object has been created. The IOLoop is blocked and no
> > > more requests can be processed until the GridFS object is created. In
> > > Motor, on the other hand, you need to open it asynchronously:
> > > On the other hand, if you look at the code for the regular PyMongo
> > > gridfs.GridFS constructor, you'll see all it does is an ensure_index(),
> > > which (assuming the index is already created) is so fast that it's
> > probably
> > > not a problem. *Reading* from a PyMongo GridFS object, however, will
> > block
> > > the IOLoop until complete, which for large files *will* be a problem.
> > > On Saturday, October 6, 2012 3:27:01 PM UTC-7, aliane abdelouahab wrote:
> > > > am sorry for asking this dumb question, but can i use this technique
> > > > (which is used in the examples of projects made by tornado users) to
> > > > make inheritence?
> > > > class BaseHandler(tornado.web.RequestHandler):
> > > > def get_current_user(self):
> > > > user = self.get_secure_cookie("current_user") or False
> > > > if not user: return None
> > > > return tornado.escape.json_decode(user)
> > > > if i use the first technique, then i will add the db=db ?
> > > > On 6 oct, 22:59, "A. Jesse Jiryu Davis" <ajesseda...@gmail.com> wrote:
> > > > > I wrote up a tutorial on Motor, my MongoDB driver for Tornado: