GithubHelp home page GithubHelp logo

node-mongodb's Introduction

NAME

node-mongodb - An asynchronous Node interface to MongoDB

SYNOPSYS

var sys     = require("sys");
var mongodb = require("../lib/mongodb");

var mongo = new mongodb.MongoDB();

mongo.addListener("close", function () {
	sys.puts("Closing connection!");
});

mongo.addListener("connection", function () {
	var widgets = mongo.getCollection('widgets');

	mongo.getCollections(function (collections) {
		sys.puts("the collections in the db are " + JSON.stringify(collections));
	});

	// remove widgets with shazbot > 0
	widgets.remove({ shazbot: { "$gt": 0 } });

	// actually, just remove all widgets
	widgets.remove();

	widgets.count(null, function(count) {
		widgets.insert({ foo: 1,    shazbot: 1 });
		widgets.insert({ bar: "a",  shazbot: 2 });
		widgets.insert({ baz: 42.5, shazbot: 0 });

		// count all the widgets
		widgets.count(null, function (count) {
			sys.puts("there are " + count + " widgets");
		});

		// count widgets with shazbot > 0
		widgets.count({ shazbot: { "$gt": 0 } }, function (count) {
			sys.puts(count + " widget shazbots are > 0");
		});

		// count shazbots less than or equal to 1
		widgets.count({ shazbot: { "$lte": 1 } }, function (count) {
			sys.puts(2 == count);
		});

		// return all widgets
		widgets.find(null, null, function (results) {
			// ...
		});

		// return widgets with shazbot > 0
		widgets.find({ shazbot: { "$gt": 0 } }, null, function (results) {
			// ...
		});

		// return only the shazbot field of every widget
		widgets.find({}, { "shazbot": true }, function (results) {
			// update shazbot of first document with shazbot 0 to 420
			widgets.update({ shazbot: 0 }, { shazbot: 420 });

			widgets.find(null, null, function (results) {
				results.forEach(function(r) {
					// ...
				});

				// close the connection
				mongo.close();
			});
		});
	});
});

mongo.connect({
	hostname: '127.0.0.1',
	port: 27017,
	db: 'mylittledb'
});

DESCRIPTION

This is an attempt at MongoDB bindings for Node. The important thing here is to ensure that we never let ourselves or any libraries block on IO. As such, I've tried to do my best to make sure that connect() and recv() never block, but there may be bugs. The MongoDB C drivers are used to interface with the database, but some core functions needed to be rewritten to operate in a non-blocking manner.

Installation

  • Make sure you have git installed.
  • ./update-mongo-c-driver.sh
  • node-waf configure build
  • ./run-tests.sh

BUGS

This package is EXPERIMENTAL, with emphasis on MENTAL. I am working on this in my spare time to learn the Node, v8 and MongoDB API's.

The error handling in this extension needs to be improved substantially. Be warned.

I would appreciate any and all patches, suggestions and constructive criticisms.

ACKNOWLEDGEMENTS

  • ryah's Node postgres driver was the foundation for this extension
  • MongoDB C drivers
  • The people in #node.js and #mongodb on freenode for answering my questions

SEE ALSO

AUTHOR

Orlando Vazquez ([email protected])

node-mongodb's People

Contributors

orlandov avatar morganrallen avatar

Watchers

Chuck Yang avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.