Mongo newcomer - which driver to choose?

33 views
Skip to first unread message

Michal Stefanow

unread,
May 13, 2015, 11:04:04 AM5/13/15
to mongoo...@googlegroups.com
Hello Mongo,

I have a general question, maybe you could point me a right direction.

Is there any wiki page / blog article that would explain to Mongo newcomer whether I should use Mongoose driver over the native one?


The native driver is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoose.

I'm currently using ... and I'm also leveraging ... - all that fancy mess - and I feel limited with my current DB solution, therefore seriously considering Mongo.

Maybe I could discuss my requirements and then choose the right driver?

Another quote from the docs:
thriving open source community and includes advanced schema-based features such as async validation, casting, object life-cycle management, pseudo-joins, and rich query builder support

In other words I'm seeking advice :) As a newcomer I would prefer simplicity but then - I may feel limited at certain point along the line. 

Thank you in advance
Michal Stefanow

Jason Crawford

unread,
May 13, 2015, 12:41:07 PM5/13/15
to mongoo...@googlegroups.com
For what it's worth, I tried to start with the raw Mongo driver, thinking I might switch to Mongoose later if needed. But I found it so hard to get started, mostly based on lack of documentation, that I just switched to Mongoose right away, which had a cleaner API and better documentation (at least, that's how it seemed to me at the time).

-Jason

--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nathan White

unread,
May 13, 2015, 8:51:53 PM5/13/15
to mongoo...@googlegroups.com
It really depends on your needs.

Mongoose has a great community, tons of plugins and actively developed with support from 10gen engineers. If your coming from a traditional ORM type system then mongoose will probably offer the smoothest transition. Mongoose offers some nice type safety and validation along with trying hard to make operations atomic by default.

Mongoose may not be a good fit if:

* simplicity is paramount. As a mongoose project grows with multiple developers and business rules. Behavior can be harder to track down because of the pre / post hooks or someone slapping in a plugin. This isn't mongoose specific but something to be mindful of.

* ad hoc schemas. You can do it with mongoose but it's kinda a pain. It can also be largely solved with the Mixed data type. But dynamic collections isn't a strong suit of mongoose.

* Your task is heavy in writes. More importantly, data generated from introspection like map reduce, groups and aggregation. While mongoose can do this the ad hoc issue above can make it cumbersome at times. If your tasks are creating stable schemas in defined collections it's a non issue.

* speed is super critical. Mongoose wraps everything which adds a bit of overhead. Mongoose does offer lean to bypass this. Personally I don't think this is a great argument against it unless you have some serious traffic.


Personally I would use mongoose. You can always add a lower level driver for specialized tasks later. It doesn't have to be an all or nothing approach ;-)
--

Ryan Wheale

unread,
May 14, 2015, 4:40:46 PM5/14/15
to mongoo...@googlegroups.com
I have found that knowing how the native driver works allows you to really leverage Mongoose to it's full ability as mongoose does a lot of internal processing.  As Nathan mentioned, you can do "lean" queries, which bypasses a lot of the processing mongoose does and is the easiest and most substantial performance win.  Lean queries return plain JS objects instead of mongoose documents.  The new version of mongoose has a hydrate() method that lets you convert a plain JS object into a mongoose document instance if you need - letting you be in control of the extra processing.

Mongoose models also expose the native driver so you can talk straight to mongo if you want.  For example, I configure my User models never to select the password or salt fields... but I can use the native driver in those rare situations where I need that information.

The populate() method will save you hundreds of lines of code.  Again, understanding how the native driver works will help you use populate() most efficiently as it is very easy to kill your performance with this feature.

~Ryan

Reply all
Reply to author
Forward
0 new messages