• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    C++
  • Created almost 15 years ago
  • Updated over 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

mongodb bindings for node.js

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])

More Repositories

1

vimfluence

Edit Confluence Wikis with Vim
Shell
75
star
2

node-riak

Riak client for Node
JavaScript
26
star
3

azathoth

HTTP load/traffic generator and benchmark tool built on Node.js
JavaScript
25
star
4

node-mpd

Node.js client library to MPD (Music Player Dæmon)
JavaScript
14
star
5

blogjob

Catalyst blog webapp (powered by MongoDB!)
CSS
9
star
6

node-scgi

A Javascript SCGI application server for Node.js
JavaScript
6
star
7

couchwiki

a wiki implementation using pylons and couchdb
JavaScript
5
star
8

node-vmdk

nodejs interface to streamOptimized vmdk files
JavaScript
5
star
9

hbridge

Use an Arduino to bi-directionally control 2 DC motors with an L293D H-Bridge.
5
star
10

pyscgi_wsgi

Bridge the gap between SCGI and WSGI applications
Python
3
star
11

DialogueEngine

a prototype game dialogue engine in Python
Python
3
star
12

skeleton-markdown-man-page

A template man-style page formatted in Markdown
3
star
13

gitrest

A proof of concept RESTful interface to git
Python
3
star
14

node-xmpp-bot

An XMPP bot written using Node
JavaScript
3
star
15

Legion-AWS-MapReduce

Distributed blender rendering with Amazon Elastic MapReduce
Perl
3
star
16

node-sysevent

Node.js interface to sysevent facilities on Illumos and related systems.
C++
3
star
17

node-hydracp

spawn and communicate with child processes
JavaScript
2
star
18

2wycked

my personal site
2
star
19

plex

a fork of a python lexing package
2
star
20

Legion-JobQueue

A distributed renderer for Blender
Perl
2
star
21

arma3-dedicated-linux-server-setup

arma3-dedicated-linux-server-setup
Shell
2
star
22

Catalyst-Engine-SCGI

An SCGI Engine for the Perl Catalyst framework
Perl
2
star
23

parpg-game

post apolcalyptic role playing game
Python
2
star
24

legion-python

distributed render manager for blender built on the twisted server framework
Python
2
star
25

pastique

syntax highlighting nopaste application
JavaScript
2
star
26

at-ar

All Terrain Autonomous Rover
2
star
27

eris

Orlando's experiment with lexical analysis and AST
2
star
28

stconfig

Socialtext Developer Config Tools
Vim Script
2
star
29

Legion-Web

CSS
1
star
30

jsl.vim

1
star
31

objectparty

a simple python object store inspired by kiokudb
Python
1
star
32

Catalyst-Engine-SCGI-PreFork

An pre-forking SCGI Engine for the Perl Catalyst framework
Perl
1
star
33

node-amqp-plus

additional amqp functionality
JavaScript
1
star
34

node-eio-test

C++
1
star
35

jsstyle.vim

jsstyle quickfix plugin for vim (based on the jshint.vim plugin)
Vim Script
1
star
36

jspon

jspon referencing in python - don't use, due to python's lack of support for weakrefs to native types this leaks memory
Python
1
star