MongoDB Native Driver for Node.js Speeds Up Results - Application Development - News & Reviews - eWeek.com | eWeek

Download the Driver From GitHub

Download the Driver From GitHub
Écrit par
Jeff Cogswell
Jeff Cogswell
May 16, 2012
2 minute read
eWeek Le contenu et les recommandations de produits sont indépendants de la rédaction. Nous pouvons gagner de l'argent lorsque vous cliquez sur des liens vers nos partenaires. En savoir plus


Download the Driver From GitHub

Linked Data

The driver is readily available for download on github, in the mongodb section.


Accessing the Documentation

2

The link on the driver page takes you to the official documentation, which includes a complete description of the entire API.


Installing the Driver

3

Although you can access the driver, readme and docs through github, the driver itself can be installed using the Node.js npm package manager.


Timing an Insert

4

Inserts performed well. More time was spent connecting to the database itself.


Handling Errors

5

When an error occurs, the driver gives back an error object. To inspect this, we simply sent it down to the browser and then pasted the text into the debugger so we could look at it as a JavaScript object.


Advertisement

The Stack Isnt Much Help

6

Included with the error object is a full stack trace of the actual exception that occurred. However, this isn’t very useful since it only shows the code inside the driver.


Performing Queries

7

Performing a database query requires the same approach of passing asynchronous callback functions. You can query on any of the data types as well as regular expressions.


Querying Without an Index

8

When querying a database that is not indexed, MongoDB has no choice but to do a linear search through all the records. This is not efficient and as such took several seconds to perform when searching 100,000 records.


Adding an Index

9

Adding an index in MongoDB is easy using the command prompt. This is only required once; after that, Mongo will continue to maintain the index. Therefore, there wasn’t much reason for us to do it programmatically through the driver.


Querying With an Index

10

After adding the index, the lookup was shortened dramatically, from four seconds all the way down to about 30 milliseconds.


MongoDB Code uses Callbacks

11

The code for accessing the MongoDB driver requires passing callbacks into the function calls. These callbacks allow for asynchronous operations to occur.

eWeek Logo

eWeek has the latest technology news and analysis, buying guides, and product reviews for IT professionals and technology buyers. The site's focus is on innovative solutions and covering in-depth technical content. eWeek stays on the cutting edge of technology news and IT trends through interviews and expert analysis. Gain insight from top innovators and thought leaders in the fields of IT, business, enterprise software, startups, and more.

Propriété de TechnologyAdvice. © 2026 TechnologyAdvice. Tous droits réservés

Divulgation publicitaire : Certains des produits qui apparaissent sur ce site proviennent d'entreprises dont TechnologyAdvice reçoit une compensation. Cette compensation peut influencer la façon dont les produits apparaissent sur ce site, notamment l'ordre dans lequel ils apparaissent. TechnologyAdvice n'inclut pas toutes les entreprises ou tous les types de produits disponibles sur le marché.