npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

node_mongodb_wrapper

v0.4.7

Published

Fork of node-mongodb-wrapper

Downloads

1

Readme

node-mongodb-wrapper

A wrapper for node-mongodb-native as close as possible to the native javascript driver. Why learn two interfaces?

Yes, we know other people are doing the same thing. This one has been easier to use.

Features

  1. Minimal interface closely matching the command-line driver: http://www.mongodb.org/display/DOCS/Manual
  2. Lazy open/close of connections
  3. Most features of node-mongodb-native

Installation

Usage

  1. You have to tell the db object which collections you're about to use (Harmony Proxies, I need you!)
  2. You have to provide callbacks on "actionable" calls (toArray, count, but not find)
  3. Otherwise, just like the native javascript driver

For more examples, please look at the test suite

Documentation

Remember the guiding principle: the syntax exactly matches the command-line driver, except you pass a call back to any function that hits the database.

Connecting

mongo.db(host, port, dbname, [prefix], [username], [password]) - returns an unopened database object.

  • If prefix is specified all collections will use the prefix in mongo, but you refer to them without the prefix in node.
  • If username and password are specified, it will attempt to authenticate.

db.collection(name) - Returns a Collection object. Also creates db[name] so you can do this:

db.collection('users')
db.users.count(cb)

Replica Sets

Replica sets are also supported with an alternate function signature:

var hostsArray = [
  // opts is a hash of mongodb-native server opts: http://mongodb.github.com/node-mongodb-native/api-generated/server.html
  // also optional
  {host: "host1", port: 27017, opts: {}},
  {host: "host1", port: 27018, opts: {}},
  ...
]
// other replica set opts, such as read_secondary, are passed in here
// these opts are also passed to each mongodb-native server object, so you can have defaults for your servers
var opts = {rs_name: "myReplicaSet"}

mongo.db(hostsArray, opts, dbname, [prefix], [username], [password])

Authentication

db.auth(username, password, cb) - You can pass username and password into mongo.db instead of calling this manually

db.addUser(username, password, cb)

db.removeUser(username, password, cb)

Database

db.dropDatabase(cb)

db.lastError(cb) - cb(err, lastError)

db.eval(code, [parameters], cb)

db.createCollection(name, options, cb) - allows you to create a collection by hand if you want to specify the options

Collection

collection.ensureIndex(index, options, cb)

collection.dropIndexes(cb)

collection.renameCollection(newName, dropTarget, cb)

collection.insert(doc(s), cb)

collection.remove(selector, cb)

collection.drop(cb)

collection.save(doc, cb)

collection.update(selector, updates, [upsert], [multi], cb)

collection.count(cb)

collection.findAndModify(options, cb)

collection.find(selector, fields) - Returns a Cursor

collection.findOne(selector, fields, cb)

collection.group(options, cb)

collection.mapReduce(map, reduce, options, cb) - map and reduce can be functions, it will toString them for you.

collection.distinct(key, [query], cb)

Cursor

cursor.limit(num)

cursor.skip(num)

cursor.sort({field:1})

cursor.next(cb)

cursor.explain(cb)

cursor.toArray(cb)

cursor.count(cb)

Useful Exports

mongo.ObjectID - you need to wrap any string ids in this class to match on _id