Easy and light weight interface wrapping the native node.js MongoDB driver, the mongodb module.
Simple wrapper to use basic insert/find/modify/delete functions. Ability to access native collection and database objects for more advanced operations.
By default uses shortId so that new objects have short strings as _ids instead of ObjectIDs. Also by default has protections in place to prevent accidentally clobbering an object on update. Optional ability to require the fields to retrieve for find() operations to be specified (good for performance!) and many other features as well!
Provides the following functions:
As well as access to the native collection and database objects:
Ability to enable/disable (good for maintenance mode)
npm install ezmongo
Constructs an EzMongo instance. The only required option is database, the rest have defaults.
var ezMongo = database: 'ezMongoTestDb';// below will query as soon as DB is connectedezMongo;
Looks up a single document from a collection. Callback with the document if found, or null if not. If multiple documents match the search and no sort is provided, the document returned is non-deterministic and up to the database.
Looks up multiple documents from a collection. Callback with the array of found documents. If no documents are found the array will be empty.
Updates a single document. Callback with number of documents modified: 1 if a document modified, 0 if not. If multiple documents match the search, the one that will be modified is non-deterministic and up to the database.
Updates multiple documents. Callback with number of documents modified.
Removes a single document. Callback with number of documents removed: 1 if removed, 0 if not. If multiple documents match the search, the one that will be removed is non-deterministic and up to the database.
Removes multiple documents. Callback with number of documents removed.
Inserts documents into the database. If documents don't have an _id, one will be automatically generated either by using shortId, or if useShortId constructor option was false by the database. Callback with the _id, or array of _ids of the newly inserted documents.
Provides access to the native collection object for a collection. Callback with the native collection.
Provides access to the native database object. Will attempt to connect. Callback with the native database.
Effectively disables the database as any subsequent EzMongo commands (other than enable/disable) will result in an error. Callback with whether or not the database was already disabled.
Effectively enables the database, with EzMongo commands executing as intended. Callback with whether or not the database was already enabled.
Testing uses nodeunit, which you can install globally
npm install -g nodeunit
To run the tests, execute:
This module is not yet fully covered by tests. Particularly the various constructor options. While uses in production also help tease out errors, expanded test coverage is a goal.
Version 0.0.6 has been tested and works with node version 0.12.4 and MongoDB 3.0.3. If you use older versions you may need an older version of ezmongo.
EzMongo was originally created for Node Knockout 2011 winner for Most Fun, Doodle Or Die and is still used today. Millions of hilarious doodles have been saved and accessed using EzMongo. EzMongo is also used for projects by the Video Blocks team. Unlimited downloads stock video, after effects templates, and more for one flat price.