1

I'm now learning how to use MongoDB in Node.js, but as long as I know, there are two ways to write the code.

One (on some books and online blogs):

var Db = require('mongodb').Db, Connection = require('mongodb').Connection, Server = require('mongodb').Server;

Two (Github page and its documentation page on 10gen):

var MongoClient = require('mongodb').MongoClient;

Why does the disparity occur and which one should I take if there are any differences other than syntax? Perhaps it's due to different versions of the module, but if so on what number I have to take one over the other?

Thanks.

2
  • MongoClient is a recent addition to all the drivers and is now the generally preferred way to go. Commented Aug 15, 2013 at 22:00
  • If it's recommended by 10gen, you shouldn't consider another option :) Commented Aug 15, 2013 at 22:53

1 Answer 1

1

MongoClient is the new prefered way for all the different drivers. It has acknowledged (safe) writes on by default and should be the general interface to MongoDB. See http://blog.mongodb.org/post/36666163412/introducing-mongoclient for more information about how and why.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.