Close
  • Latest News
  • Artificial Intelligence
  • Video
  • Big Data and Analytics
  • Cloud
  • Networking
  • Cybersecurity
  • Applications
  • IT Management
  • Storage
  • Sponsored
  • Mobile
  • Small Business
  • Development
  • Database
  • Servers
  • Android
  • Apple
  • Innovation
  • Blogs
  • PC Hardware
  • Reviews
  • Search Engines
  • Virtualization
Read Down
Sign in
Close
Welcome!Log into your account
Forgot your password?
Read Down
Password recovery
Recover your password
Close
Search
Logo
Subscribe
Logo
  • Latest News
  • Artificial Intelligence
  • Video
  • Big Data and Analytics
  • Cloud
  • Networking
  • Cybersecurity
  • Applications
  • IT Management
  • Storage
  • Sponsored
  • Mobile
  • Small Business
  • Development
  • Database
  • Servers
  • Android
  • Apple
  • Innovation
  • Blogs
  • PC Hardware
  • Reviews
  • Search Engines
  • Virtualization
More
    Subscribe
    Home Applications
    • Applications
    • Database
    • Development
    • Servers

    MongoDB Driver Delivers Effective Support for Node.js

    Written by

    Jeff Cogswell
    Published May 16, 2012
    Share
    Facebook
    Twitter
    Linkedin

      eWEEK content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

      On April 25, 10gen released the first official MongoDB driver for Node.js. Although this is the first official release, the open-source MongoDB driver for Node.js has been in development and early release for more than two years. The new driver works well and provides full access to nearly all MongoDB features that work within a JavaScript program that is running under Node.js.

      To see images of MongoDB in action, click here

      Working with version 1.0.0, eWEEK Labs took a comprehensive look at the main features that make up the MongoDB driver for Node.js, including available database features, the driver API, and overall performance based on how fast the calls were made.

      I tested the MongoDB driver on a Rackspace Ubuntu 11.04 server, running Node.js with the Express framework. For timing, I used the node-microtime module. For source-code editing, I used the Cloud9 integrated development environment (IDE), but to run the applications, I used the bash shell directly.

      As with most Node modules, installation was quick and smooth with the Node Package Manager (NPM) installer. I chose to install the packages globally using the €œg€ option of NPM. After creating the initial express project, I linked the package to the project with the NPM link command.

      The MongoDB driver for Node.js supports nearly all the operations that MongoDB itself supports. I tested many of them, starting with a basic insert operation. Because I worked in Node.js, which is an implementation of JavaScript, I was able to define my objects in precisely the same notation that MongoDB uses. While I was at it, I included timing code so that I could test how fast it is. I put this code inside an HTTP Get operation.

      The code makes heavy use of the Node.js approach of asynchronous callback functions so that the code does not block while the database operations are performing. I opened the database and passed in a function that gets called after the database is opened. That€™s the first callback and is also where I retrieve the collection.

      This callback approach can be a little confusing to less-experienced coders. The idea is that Node.js is fully asynchronous and nonblocking; as such, I passed in a function that gets called only after the database is open. Meanwhile, the rest of the other function continues on its way, and depending on how long the I/O takes, likely finishes before the database operations are even complete. This is the norm for Node.js programming and is the approach upon which the entire library is built.

      Typically, MongoDB programming, standard database operations (create, insert, update and delete) run on a collection object. IT developers who have used a MongoDB driver in another language (such as C# or Ruby) should have no trouble applying these same operations using the Node.js driver

      Inserts Take Less Than a Millisecond}</p>
      <p>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

      ;

      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
      Jeff Cogswell
      Jeff Cogswell is the author of Designing Highly Useable Software (http://www.amazon.com/dp/0782143016) 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.

      Get the Free Newsletter!

      Subscribe to Daily Tech Insider for top news, trends & analysis

      Get the Free Newsletter!

      Subscribe to Daily Tech Insider for top news, trends & analysis

      MOST POPULAR ARTICLES

      Artificial Intelligence

      9 Best AI 3D Generators You Need...

      Sam Rinko - June 25, 2024 0
      AI 3D Generators are powerful tools for many different industries. Discover the best AI 3D Generators, and learn which is best for your specific use case.
      Read more
      Cloud

      RingCentral Expands Its Collaboration Platform

      Zeus Kerravala - November 22, 2023 0
      RingCentral adds AI-enabled contact center and hybrid event products to its suite of collaboration services.
      Read more
      Artificial Intelligence

      8 Best AI Data Analytics Software &...

      Aminu Abdullahi - January 18, 2024 0
      Learn the top AI data analytics software to use. Compare AI data analytics solutions & features to make the best choice for your business.
      Read more
      Latest News

      Zeus Kerravala on Networking: Multicloud, 5G, and...

      James Maguire - December 16, 2022 0
      I spoke with Zeus Kerravala, industry analyst at ZK Research, about the rapid changes in enterprise networking, as tech advances and digital transformation prompt...
      Read more
      Video

      Datadog President Amit Agarwal on Trends in...

      James Maguire - November 11, 2022 0
      I spoke with Amit Agarwal, President of Datadog, about infrastructure observability, from current trends to key challenges to the future of this rapidly growing...
      Read more
      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.

      Facebook
      Linkedin
      RSS
      Twitter
      Youtube

      Advertisers

      Advertise with TechnologyAdvice on eWeek and our other IT-focused platforms.

      Advertise with Us

      Menu

      • About eWeek
      • Subscribe to our Newsletter
      • Latest News

      Our Brands

      • Privacy Policy
      • Terms
      • About
      • Contact
      • Advertise
      • Sitemap
      • California – Do Not Sell My Information

      Property of TechnologyAdvice.
      © 2024 TechnologyAdvice. All Rights Reserved

      Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.

      ×