Skip to content

Commit

Permalink
Updated docs for 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Nov 27, 2012
1 parent 164d7de commit d3523d5
Show file tree
Hide file tree
Showing 71 changed files with 2,680 additions and 2,802 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: bed7698c910c72d9ece4e11878af20bd
config: e54c79873cefa79d9d8d3fbf71d3ab21
tags: fbb0d17656682115ca4d033fb2f83ba1
162 changes: 97 additions & 65 deletions _sources/api-articles/nodekoarticle1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,40 @@ Getting that connection to the database

.. code-block:: javascript

var mongo = require('mongodb'),
Server = mongo.Server,
Db = mongo.Db;
// Retrieve
var MongoClient = require('mongodb').MongoClient;

var server = new Server('localhost', 27017, {auto_reconnect: true});
var db = new Db('exampleDb', server);

db.open(function(err, db) {
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(!err) {
console.log("We are connected");
}
});



Let's have a quick look at the simple connection. The **new Server(...)** sets up a configuration for the connection and the **auto_reconnect** tells the driver to retry sending a command to the server if there is a failure. Another option you can set is **poolSize** , this allows you to control how many tcp connections are opened in parallel. The default value for this is 5 but you can set it as high as you want. The driver will use a round-robin strategy to dispatch and read from the tcp connection.
Let's have a quick look at how the connection code works. The **Db.connect**
method let's use use a uri to connect to the Mongo database, where
**localhost:27017** is the server host and port and **exampleDb** the db
we wish to connect to. After the url notice the hash containing the
**auto_reconnect** key. Auto reconnect tells the driver to retry sending
a command to the server if there is a failure during it's execution.



Another useful option you can pass in is



**poolSize** , this allows you to control how many tcp connections are
opened in parallel. The default value for this is 5 but you can set it
as high as you want. The driver will use a round-robin strategy to
dispatch and read from the tcp connection.



We are up and running with a connection to the database. Let's move on and look at what collections are and how they work.
We are up and running with a connection to the database. Let's move on
and look at what collections are and how they work.


------------------------
Expand All @@ -90,17 +104,22 @@ Mongo DB and Collections

.. code-block:: javascript

db.open(function(err, db) {
if(!err) {
db.collection('test', function(err, collection) {});
// Retrieve
var MongoClient = require('mongodb').MongoClient;

db.collection('test', {safe:true}, function(err, collection) {});
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) { return console.dir(err); }

db.createCollection('test', function(err, collection) {});
db.collection('test', function(err, collection) {});

db.createCollection('test', {safe:true}, function(err, collection) {});
}
});
db.collection('test', {w:1}, function(err, collection) {});

db.createCollection('test', function(err, collection) {});

db.createCollection('test', {w:1}, function(err, collection) {});

});



Expand Down Expand Up @@ -160,20 +179,24 @@ And then there was CRUD

.. code-block:: javascript

db.open(function(err, db) {
if(!err) {
db.collection('test', function(err, collection) {
var doc1 = {'hello':'doc1'};
var doc2 = {'hello':'doc2'};
var lotsOfDocs = [{'hello':'doc3'}, {'hello':'doc4'}];
// Retrieve
var MongoClient = require('mongodb').MongoClient;

collection.insert(doc1);
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) { return console.dir(err); }

collection.insert(doc2, {safe:true}, function(err, result) {});
var collection = db.collection('test');
var doc1 = {'hello':'doc1'};
var doc2 = {'hello':'doc2'};
var lotsOfDocs = [{'hello':'doc3'}, {'hello':'doc4'}];

collection.insert(doc1);

collection.insert(doc2, {w:1}, function(err, result) {});

collection.insert(lotsOfDocs, {w:1}, function(err, result) {});

collection.insert(lotsOfDocs, {safe:true}, function(err, result) {});
});
}
});


Expand Down Expand Up @@ -226,22 +249,25 @@ And then there was CRUD

.. code-block:: javascript

db.open(function(err, db) {
if(!err) {
db.collection('test', function(err, collection) {
var doc = {mykey:1, fieldtoupdate:1};
// Retrieve
var MongoClient = require('mongodb').MongoClient;

// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) { return console.dir(err); }

var collection = db.collection('test');
var doc = {mykey:1, fieldtoupdate:1};

collection.insert(doc, {safe:true}, function(err, result) {
collection.update({mykey:1}, {$set:{fieldtoupdate:2}}, {safe:true}, function(err, result) {});
});
collection.insert(doc, {w:1}, function(err, result) {
collection.update({mykey:1}, {$set:{fieldtoupdate:2}}, {w:1}, function(err, result) {});
});

var doc2 = {mykey:2, docs:[{doc1:1}]};
var doc2 = {mykey:2, docs:[{doc1:1}]};

collection.insert(doc2, {safe:true}, function(err, result) {
collection.update({mykey:2}, {$push:{docs:{doc2:1}}, {safe:true}, function(err, result) {});
});
});
};
collection.insert(doc2, {w:1}, function(err, result) {
collection.update({mykey:2}, {$push:{docs:{doc2:1}}, {w:1}, function(err, result) {});
});
});


Expand Down Expand Up @@ -294,21 +320,24 @@ And then there was CRUD

.. code-block:: javascript

db.open(function(err, db) {
if(!err) {
db.collection('test', function(err, collection) {
var docs = [{mykey:1}, {mykey:2}, {mykey:3}];
// Retrieve
var MongoClient = require('mongodb').MongoClient;

// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) { return console.dir(err); }

var collection = db.collection('test');
var docs = [{mykey:1}, {mykey:2}, {mykey:3}];

collection.insert(docs, {safe:true}, function(err, result) {
collection.insert(docs, {w:1}, function(err, result) {

collection.remove({mykey:1});
collection.remove({mykey:1});

collection.remove({mykey:2}, {safe:true}, function(err, result) {});
collection.remove({mykey:2}, {w:1}, function(err, result) {});

collection.remove();
});
});
};
collection.remove();
});
});


Expand Down Expand Up @@ -356,24 +385,27 @@ Time to Query

.. code-block:: javascript

db.open(function(err, db) {
if(!err) {
db.collection('test', function(err, collection) {
var docs = [{mykey:1}, {mykey:2}, {mykey:3}];
// Retrieve
var MongoClient = require('mongodb').MongoClient;

// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) { return console.dir(err); }

var collection = db.collection('test');
var docs = [{mykey:1}, {mykey:2}, {mykey:3}];

collection.insert(docs, {safe:true}, function(err, result) {
collection.insert(docs, {w:1}, function(err, result) {

collection.find().toArray(function(err, items) {});
collection.find().toArray(function(err, items) {});

var stream = collection.find({mykey:{$ne:2}}).streamRecords();
stream.on("data", function(item) {});
stream.on("end", function() {});
var stream = collection.find({mykey:{$ne:2}}).streamRecords();
stream.on("data", function(item) {});
stream.on("end", function() {});

collection.findOne({mykey:1}, function(err, item) {});
collection.findOne({mykey:1}, function(err, item) {});

});
});
};
});
});


Expand Down
57 changes: 28 additions & 29 deletions _sources/api-articles/nodekoarticle2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ A simple example

.. code-block:: javascript

var mongo = require('mongodb'),
Server = mongo.Server,
Db = mongo.Db,
Grid = mongo.Grid;
var MongoClient = require('mongodb').MongoClient,
Grid = mongo.Grid;

var server = new Server('localhost', 27017, {auto_reconnect: true});
var db = new Db('exampleDb', server);
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) return console.dir(err);

db.open(function(err, db) {
if(!err) {
var grid = new Grid(db, 'fs');
var buffer = new Buffer("Hello world");
grid.put(buffer, {metadata:{category:'text'}, content_type: 'text'}, function(err, fileInfo) {
if(!err) {
console.log("Finished writing file to Mongo");
}
});
}
var grid = new Grid(db, 'fs');
var buffer = new Buffer("Hello world");
grid.put(buffer, {metadata:{category:'text'}, content_type: 'text'}, function(err, fileInfo) {
if(!err) {
console.log("Finished writing file to Mongo");
}
});
});


Expand Down Expand Up @@ -80,18 +76,22 @@ A simple example

.. code-block:: javascript

db.open(function(err, db) {
if(!err) {
var grid = new Grid(db, 'fs');
var buffer = new Buffer("Hello world");
grid.put.(buffer, {metadata:{category:'text'}, content_type: 'text'}, function(err, fileInfo) {
grid.get(fileInfo._id, function(err, data) {
console.log("Retrieved data: " + data.toString());
grid.delete(fileInfo._id, function(err, result) {
});
});
var MongoClient = require('mongodb').MongoClient,
Grid = mongo.Grid;

// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) return console.dir(err);

var grid = new Grid(db, 'fs');
var buffer = new Buffer("Hello world");
grid.put.(buffer, {metadata:{category:'text'}, content_type: 'text'}, function(err, fileInfo) {
grid.get(fileInfo._id, function(err, data) {
console.log("Retrieved data: " + data.toString());
grid.delete(fileInfo._id, function(err, result) {
});
});
}
});
});


Expand Down Expand Up @@ -193,8 +193,7 @@ Advanced GridFS or how not to run out of memory

.. code-block:: javascript

var gridStore = new GridStore(db, fileId, "r");
gridStore.open(function(err, gridStore) {
new GridStore(db, fileId, "r").open(function(err, gridStore) {
var stream = gridStore.stream(true);

stream.on("data", function(chunk) {
Expand Down
10 changes: 10 additions & 0 deletions _sources/api-bson-generated/bson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Calculate the bson size for a passed in Javascript object.
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -118,6 +119,7 @@ Serialize a Javascript object using a predefined Buffer and index into the buffe
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -176,6 +178,7 @@ Serialize a Javascript object.
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -232,6 +235,7 @@ Options
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -301,6 +305,7 @@ Options
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -361,6 +366,7 @@ Options
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -426,6 +432,7 @@ Options
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -491,6 +498,7 @@ Serialize a Javascript object.
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -538,6 +546,7 @@ Calculate the bson size for a passed in Javascript object.
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down Expand Up @@ -586,6 +595,7 @@ Serialize a Javascript object using a predefined Buffer and index into the buffe
.. code-block:: javascript

var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Expand Down
Loading

0 comments on commit d3523d5

Please sign in to comment.