Mongoose vs mongodb native driver – what to prefer?
Paul Shan 7th Jun 2015
Mongoose or mongodb native driver, which one to use? This is one of the initial queries for a node-mongo developer; and probably one of the most important ones. Because one use Object Relational Mapping (ORM) and another Object Document Mapping (ODM); so chainging the driver later on in your project can immensly increase your work. So you need to decide the driver very wisely.
| 
 Mongoose  | 
 Mongodb native  | 
|
| 
 Object mapping  | 
 ORM  | 
 ODM  | 
| 
 Schema  | 
 Mandatory  | 
 Not necessary  | 
| 
 Performance / processing time  | 
 Not bad  | 
 Excellent  | 
| 
 Development time  | 
 Fast  | 
 Average  | 
| 
 Default promise  | 
 No  | 
 No  | 
| 
 Maintainability  | 
 Easy  | 
 Little hard  | 
| 
 Learning curve  | 
 Little high  | 
 Low  | 
| 
 Community  | 
 Good  | 
 Good  | 
Below is a point by point comparison of the two drivers. Try to relate the scenario of your project with them, I hope you will be able to find out which one is the best for you.
ORM or ODM – What is good for you?
ORM or Object Relational Mapping is based on the principal of having strict models or schemas. In ORM, which mongoose is using, you have to define your schema structure. There has to be a fixed schema.
ODM or Object Document Mapping is the core concept of mongo itself; and same goes with mongodb native driver. Mongodb doesn't need any fixed schema. You can insert or update whatever and however you want.
Mongoose:
So, is it a disadvantage to have a fixed Schema? No. Certainly not. This even gives a structure and more maitainability to your application code. This doesn't hamper the scalability feature of mongo; because if in future if your app grows and there is a need to add few more fields, you can modify the schema and work accordingly (which is certainly not a bis task).
Eg: If you want to develop a website to sell movie tickets, to store the inventories it's better to have a fixed schema. Cause you know that the inventories will have fixed properties.
Mongodb native:
There are situation when a fixed schema can become a curse. Suppose you have an online glossary shop. So will you create a schema for every different kind of product; cause all of them have different property sets? Probably this is where you would like to go with a document mapping way and select mongodb native for that.
Performance & Development time
Well, in terms of performace, the low level things are always better; no doubt. But you may face other overheads. Fast processing time may slow down your development time and also the vice versa. Lets see how mongoose and mongodb native stands against performance and development time.
Mongoose:
If you are developing an app for a client which wont be having millions of users or very high read/write concurrency, and you want to develop it fast, than there is no reason not to select mongoose. Development with mongoose is really fast. You don't need to take the overhead of creating a connection, closing it in proper time. Optimizing the connection, making promises etc. Abstruction layer of mongoose does all these for you.
Mongodb native:
CRUD operations using mongodb native is really faster than mongoose. If you digg in the internet you will find stats also; something like this http://codeandcodes.com/tag/mongoose-vs-mongodb-native/
But if you do a single db operation in each web request, and follow the conventional ways of mongodb (opening a db connection, finish your operation and close it) and you have millions of concurrent requests, your app will die. Cause the proper way would be opening and closing a db connection and handle each request in optimized way. You cant just open and close it for each request. So this optimized handling need to be coded by you if you are making a performant app using mongodb native; for what you have to spend a little extra development time (it's not that hard thing to do).
Maintainability
For any long term project, maitainability is a big factor. Easy to maintain code reduces your project cost very much. When you have wrapers like mongoose which forces you to create a schema and do things with the help of models, definately gives your project a structure and thus easily maintainable. But this never means mongodb native has a disadvantage on maintainability. If you follow good coding structure, you abviously can make the app good. But the only thing is, you yourself have to write good piece of code.
Learning curve
Neither of them are hard to adopt. But in you have done operations in mongo client in your early days with mongo, than choosing mongodb native would be great for you. Cause it has the same syntax as mongo client and will take zero effort to understand the concept.
Conclusion
Till now I always prefered mongodb native. The reason is, if something is more performent, than I do not mind to put some extra effort to structure my code and optimize the behavior. But may be for any urgent deliverable project I will go with mongoose. You can choose your diver basing on the conditions and according to your situation; but the point I strongly believe is, nothing sould be more important than performance.
来自: http://voidcanvas.com/mongoose-vs-mongodb-native/
另外:
Mongoose官网: http://mongoosejs.com/index.html
还在保持更新,具体可以看它的twitter: https://twitter.com/mongoosejs
Mongoose vs mongodb native driver – what to prefer?的更多相关文章
- MongoDB Native Node.js Driver
		
写在前面 最近读<node.js学习指南>,对于mongodb没有介绍太多的工作原理,但是对于一个前端开发者,即使你还没有用过这种数据库也可以让你很好的理解和使用 一本非常好的 ...
 - MongoDB ODBC Driver for Data Integration with Power BI
		
This guide will walk you through connecting Microsoft Power BI to a MongoDB DataSet using our MongoD ...
 - 给java mongodb 官方driver 增加bean 操作
		
mongodb官方的java driver不支持直接插入java bean,只能使用DbObject的Key,Value形式进行insert,update,(c# mongodb官方driver类 ...
 - MongoDB Java Driver操作指南
		
MongoDB为Java提供了非常丰富的API操作,相比关系型数据库,这种NoSQL本身的数据也有点面向对象的意思,所以对于Java来说,Mongo的数据结构更加友好. MongoDB在今年做了一次重 ...
 - MongoDB C Driver使用教程
		
MongoDB C Driver使用教程 转载请注明出处http://www.cnblogs.com/oloroso/ 本指南提供简介 MongoDB C 驱动程序. 在 C API 的详细信息,请参 ...
 - windows平台下安装、编译、使用mongodb C++ driver
		
本博客将记录在Win8.1 ,VS2013环境下编译.配置mongodb C++ driver的流程. 1.下载预备 下载Boost:http://sourceforge.net/projects/b ...
 - php5.3新特性 之 mysql native driver(mysqlnd)
		
概述 本文主要写给sa看的.码农就不用看了. mysql native driver(mysqlnd) 自从php5.3.0开始成为官方源代码的一部分, 用来取代传统的mysql client lib ...
 - Ignoring Extra Elements in mongoDB C# Driver
		
MongoDB删除字段后会报错: Element ... does not match any field or property of class Customer. 需要在实体类增加 [BsonI ...
 - 在express中使用Mongoose连接MongoDB
		
为何要学Mongoose? Mongoose是MongoDB的一个对象模型工具,封装了MongoDB对文档的的一些增删改查等常用方法,让NodeJS操作Mongodb数据库变得更加灵活简单. 0.安装 ...
 
随机推荐
- bash编程之xargs实用技巧
			
xargs结合管道操作符|,可以完成很多看似复杂的问题: 1.快速删除所有.log日志文件 机器运行久了,就会有各式各样的日志文件,散落在各个目录下,可以利用下面的方法: find ./ -name ...
 - Access restriction: The method XXX from the type XXX is not accessible due to restriction XXX
			
插件重构的时候 遇到这个问题 Access restriction: The method setDefaultAutoCommit(boolean) from the type BasicDataS ...
 - Delphi XE 6,Rad Studio XE 6 官方下载(附破解)
			
官方光盘镜像下载: http://altd.embarcadero.com/download/radstudio/xe6/delphicbuilder_xe6_win.iso RAD Studio ...
 - IOS开发之——objective-c与javascript交互
			
原文:http://blog.csdn.net/pjk1129/article/details/6936545 在写 JavaScript 的时候,可以使用一个叫做 window 的对象,像是我们想要 ...
 - 程序员必须知道的HTML常用代码有哪些?
			
HTML即超文本标记语言,是目前应用最为广泛的语言之一,是组成一个网页的主要语言.在现今这个HTML5华丽丽地占领了整个互联网的时候,如果想要通过网页抓住浏览者的眼球光靠因循守旧是不行的,程序猿们需要 ...
 - spring源码之—Assert.notNull
			
org.springframework.util.Assert Assert翻译为中文为"断言".用过JUNIT的应该都知道这个概念了. 就是断定某一个实际的值就为自己预期想得到的 ...
 - Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式
			
from://http://blog.csdn.net/androiddevelop/article/details/11100109 相关文章列表: <Android 自动编译.打包生成apk ...
 - LeetCode——Convert Sorted List to Binary Search Tree
			
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
 - java基础之static(静态)
			
静态的属性.方法等属于类而不是对象. 静态的方法能够由类直接调用,不须要将类实例化. 本篇主要说明:1.态的代码.成员变量要比构造方法先运行. 2. 子类的构造方法会默认去调用父类的不带參数的构造方法 ...
 - linux下vi操作Found a swap file by the name
			
当我在linux下用vi打开Test.java文件时 [root@localhost tmp]# vi Test.java 会出现如下信息: E325: ATTENTION Found a swap ...