Am 22.01.2014 04:51, schrieb Kai-Heng Feng:
I want to organize my REST APIs in different modules,
I am wondering if I useconnectMongoDBin these classes (or even in functions)
are some kind of bad practice?Or should I use
connectMongoDBonce,
then pass theMongoClientthrough class constructor?Thanks!
Passing a single MongoClient instance - or, maybe even better, the
derived MongoDatabase or MongoCollection instances - to each class
is the best approach. Each MongoClient contains its own connection
pool to the DB server, so creating multiple clients will also result in
multiple connections to the DB (even though this will usually not be a
severe issue).