Inserts Take Less Than a Millisecond}

Testing the code in the browser the very first time was a bit slow (about 1,000 milliseconds), because the collection had to first be created. But upon refreshing the browser window I saw that the collection w

By Jeff Cogswell  |  Posted 2012-05-16 Print this article Print


collection.findOne(search, function(err, doc) {

In this case, one field is a string and the other is a regular expression. Without an index, it took more than 4,000 milliseconds (4 seconds) to find. I used the mongo//DESK: leave lowercase// shell to add an index. Subsequently, the query time dropped to around 0.6 milliseconds. This, of course, is a feature of MongoDB itself, but it showed how quickly a retrieval can run using the Node.js driver, as long as the database is configured properly.

In addition to the usual database operations such as inserting and querying, the MongoDB driver also includes administration functionality, which I could have used to write system administration utilities. This functionality includes adding, removing and authenticating users; enumerating the databases and collections; setting profiling levels; and so on.

Finally, one item that€™s notably missing from the driver is high-level object modeling. This is by design, as it€™s meant to be a low-level driver that only covers direct MongoDB features. If you€™re looking for modeling, I recommend using this driver in conjunction with the Mongoose library.

Jeff Cogswell is the author of Designing Highly Useable Software ( among other books and is the owner/operator of CogsMedia Training and Consulting.Currently Jeff is a senior editor with Ziff Davis Enterprise. Prior to joining Ziff, he spent about 15 years as a software engineer, working on Windows and Unix systems, mastering C++, PHP, and ASP.NET development. He has written over a dozen books.

Submit a Comment

Loading Comments...
Manage your Newsletters: Login   Register My Newsletters

Rocket Fuel