Skip to content

Commit

Permalink
Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kvalheim committed Jan 30, 2010
1 parent 2073718 commit 834106c
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 7 deletions.
4 changes: 4 additions & 0 deletions HISTORY
@@ -0,0 +1,4 @@
0.1 2010-01-30
* Initial release support of driver using native node.js interface
* Supports gridfs specification
* Supports admin functionality
124 changes: 118 additions & 6 deletions README.rdoc
@@ -1,33 +1,145 @@
= Introduction

= Installation

=== From the GitHub source
This is a node.js driver for MongoDB. It's a port (or close to a port) of the libary for ruby at http://github.com/mongodb/mongo-ruby-driver/.

A simple example of inserting a document.

var client = new Db('integration_tests_20', new Server("127.0.0.1", 27017, {}));
client.open(function(p_client) {
client.createCollection(function(r) {
client.collection(function(collection) {
for(var i = 1; i < 1000; i++) {
collection.insert(new OrderedHash().add('c', i), function(r) {});
}

collection.insert(new OrderedHash().add('a', 2), function(r) {
collection.insert(new OrderedHash().add('a', 3), function(r) {
collection.count(function(count) {
test.assertEquals(1001, count);
// Locate all the entries using find
collection.find(function(cursor) {
cursor.toArray(function(results) {
test.assertEquals(1001, results.length);
test.assertTrue(results[0] != null);

// Let's close the db
finished_test({test_insert:'ok'});
});
}, new OrderedHash());
});
});
});
}, 'test_insert');
}, 'test_insert');
});

=== GitHub information

The source code is available at http://github.com/christkv/node-mongodb-native.
You can either clone the repository or download a tarball of the latest release.

Once you have the source you can test the driver by running

$ make test_all

in the main directory. You will need to have a mongo instance running on localhost for the integration tests to pass.

= Examples

For examples look in the examples/ directory. You can execute the examples using node.

$ cd examples
$ node queries.js

= GridStore

The GridStore class allows for storage of binary files in mongoDB using the mongoDB defined files and chunks collection definition.

See the gridfs.js file under examples/ for how to use it or view the ingration tests marked with test_gs_...

= Notes

== Primary Keys
The current version does not support connection pooling, but it will be implemented
soon.

=== Primary Key Factories

== The DB Class
Defining your own primary key factory allows you to generate your own series of id's
(this could f.ex be to use something like ISBN numbers). The generated the id needs to be a 12 byte long "string".

Simple example below

// Custom factory (need to provide a 12 byte array);
CustomPKFactory = function() {}
CustomPKFactory.prototype = new Object();
CustomPKFactory.createPk = function() {
return new ObjectID("aaaaaaaaaaaa");
}

var p_client = new Db('integration_tests_20', new Server("127.0.0.1", 27017, {}), {'pk':CustomPKFactory});
p_client.open(function(p_client) {
p_client.dropDatabase(function(done) {
p_client.createCollection(function(collection) {
collection.insert({'a':1}, function(doc) {
collection.find(function(cursor) {
cursor.toArray(function(items) {
test.assertEquals(1, items.length);

finished_test({test_custom_primary_key_generator:'ok'});
p_client.close();
});
}, {'_id':new ObjectID("aaaaaaaaaaaa")});
});
}, 'test_custom_key');
});
});

=== Strict mode

Each database has an optional strict mode. If it is set then asking for a collection
that does not exist will return an Error object in the callback. Similarly if you
attempt to create a collection that already exists. Strict is provided for convenience.

var error_client = new Db('integration_tests_', new Server("127.0.0.1", 27017, {auto_reconnect: false}), {strict:true});
test.assertEquals(true, error_client.strict);
error_client.open(function(error_client) {
error_client.collection(function(collection) {
test.assertTrue(collection instanceof Error);
test.assertEquals("Collection does-not-exist does not exist. Currently in strict mode.", collection.message);
}, 'does-not-exist');

error_client.createCollection(function(collection) {
error_client.collection(function(collection) {
test.assertTrue(collection instanceof Collection);
// Let's close the db
finished_test({test_strict_access_collection:'ok'});
error_client.close();
}, 'test_strict_access_collection');
}, 'test_strict_access_collection');
});

== Cursors

= Testing
The cursors allow for the application to pull data lazily from mongoDB. The query is
deferred until you request the first object using either .each/.nextObject/.toArray.

= Documentation

Work in Progress

= Release Notes

See HISTORY

= Credits

10gen:
http://github.com/mongodb/mongo-ruby-driver/
Google:
http://code.google.com/closure/library/
Jonas Raoni Soares Silva
http://jsfromhell.com/classes/binary-parser

= License

Copyright 2009 - 2010 Christian Amor Kvalheim.
Expand Down
1 change: 0 additions & 1 deletion integration/integration_tests.js
Expand Up @@ -2992,7 +2992,6 @@ function test_custom_primary_key_generator() {
}

var p_client = new Db('integration_tests_20', new Server("127.0.0.1", 27017, {}), {'pk':CustomPKFactory});
// var p_client = new Db('integration_tests_20', new Server("127.0.0.1", 27017, {}), {});
p_client.open(function(p_client) {
p_client.dropDatabase(function(done) {
p_client.createCollection(function(collection) {
Expand Down

0 comments on commit 834106c

Please sign in to comment.