mongodb-core
Advanced tools
Comparing version 1.0.0-alpha9 to 1.0.0
@@ -30,5 +30,5 @@ var f = require('util').format | ||
/** | ||
* Creates a new MongoCR authentication mechanism | ||
* Creates a new GSSAPI authentication mechanism | ||
* @class | ||
* @return {MongoCR} A cursor instance | ||
* @return {GSSAPI} A cursor instance | ||
*/ | ||
@@ -35,0 +35,0 @@ var GSSAPI = function() { |
@@ -19,5 +19,5 @@ var f = require('util').format | ||
/** | ||
* Creates a new MongoCR authentication mechanism | ||
* Creates a new Plain authentication mechanism | ||
* @class | ||
* @return {MongoCR} A cursor instance | ||
* @return {Plain} A cursor instance | ||
*/ | ||
@@ -24,0 +24,0 @@ var Plain = function() { |
@@ -30,5 +30,5 @@ var f = require('util').format | ||
/** | ||
* Creates a new MongoCR authentication mechanism | ||
* Creates a new SSPI authentication mechanism | ||
* @class | ||
* @return {MongoCR} A cursor instance | ||
* @return {SSPI} A cursor instance | ||
*/ | ||
@@ -35,0 +35,0 @@ var SSPI = function() { |
@@ -18,5 +18,5 @@ var f = require('util').format | ||
/** | ||
* Creates a new MongoCR authentication mechanism | ||
* Creates a new X509 authentication mechanism | ||
* @class | ||
* @return {MongoCR} A cursor instance | ||
* @return {X509} A cursor instance | ||
*/ | ||
@@ -23,0 +23,0 @@ var X509 = function() { |
@@ -14,3 +14,3 @@ var inherits = require('util').inherits | ||
/** | ||
* Creates a new Pool instance | ||
* Creates a new Connection instance | ||
* @class | ||
@@ -17,0 +17,0 @@ * @param {string} options.host The server host |
@@ -1,8 +0,3 @@ | ||
var Response = require('./connection/commands').Response | ||
, GetMore = require('./connection/commands').GetMore | ||
, Query = require('./connection/commands').Query | ||
, KillCursor = require('./connection/commands').KillCursor | ||
, Long = require('bson').Long | ||
var Long = require('bson').Long | ||
, Logger = require('./connection/logger') | ||
, ReadPreference = require('./topologies/read_preference') | ||
, MongoError = require('./error') | ||
@@ -20,2 +15,36 @@ , f = require('util').format; | ||
/** | ||
* @fileOverview The **Cursor** class is an internal class that embodies a cursor on MongoDB | ||
* allowing for iteration over the results returned from the underlying query. | ||
* | ||
* **CURSORS Cannot directly be instantiated** | ||
* @example | ||
* var Server = require('mongodb-core').Server | ||
* , ReadPreference = require('mongodb-core').ReadPreference | ||
* , assert = require('assert'); | ||
* | ||
* var server = new Server({host: 'localhost', port: 27017}); | ||
* // Wait for the connection event | ||
* server.on('connect', function(server) { | ||
* assert.equal(null, err); | ||
* | ||
* // Execute the write | ||
* var cursor = _server.cursor('integration_tests.inserts_example4', { | ||
* find: 'integration_tests.example4' | ||
* , query: {a:1} | ||
* }, { | ||
* readPreference: new ReadPreference('secondary'); | ||
* }); | ||
* | ||
* // Get the first document | ||
* cursor.next(function(err, doc) { | ||
* assert.equal(null, err); | ||
* server.destroy(); | ||
* }); | ||
* }); | ||
* | ||
* // Start connecting | ||
* server.connect(); | ||
*/ | ||
/** | ||
* Creates a new Cursor, not to be used directly | ||
@@ -30,7 +59,2 @@ * @class | ||
* @param {array} [options.documents=[]] Initial documents list for cursor | ||
* @param {boolean} [options.tailable=false] Tailable flag set | ||
* @param {boolean} [options.oplogReply=false] oplogReply flag set | ||
* @param {boolean} [options.awaitdata=false] awaitdata flag set | ||
* @param {boolean} [options.exhaust=false] exhaust flag set | ||
* @param {boolean} [options.partial=false] partial flag set | ||
* @return {Cursor} A cursor instance | ||
@@ -37,0 +61,0 @@ * @property {number} cursorBatchSize The current cursorBatchSize for the cursor |
@@ -8,3 +8,3 @@ var inherits = require('util').inherits | ||
, BSON = require('bson').native().BSON | ||
, Cursor = require('../cursor') | ||
, BasicCursor = require('../cursor') | ||
, Server = require('./server') | ||
@@ -16,2 +16,21 @@ , Logger = require('../connection/logger') | ||
/** | ||
* @fileOverview The **Mongos** class is a class that represents a Mongos Proxy topology and is | ||
* used to construct connections. | ||
* | ||
* @example | ||
* var Mongos = require('mongodb-core').Mongos | ||
* , ReadPreference = require('mongodb-core').ReadPreference | ||
* , assert = require('assert'); | ||
* | ||
* var server = new Mongos([{host: 'localhost', port: 30000}]); | ||
* // Wait for the connection event | ||
* server.on('connect', function(server) { | ||
* server.destroy(); | ||
* }); | ||
* | ||
* // Start connecting | ||
* server.connect(); | ||
*/ | ||
var DISCONNECTED = 'disconnected'; | ||
@@ -155,7 +174,5 @@ var CONNECTING = 'connecting'; | ||
* @param {number} [options.reconnectTries=30] Reconnect retries for HA if no servers available | ||
* @param {number} [options.haInterval=10000] The High availability period for replicaset inquiry | ||
* @param {number} [options.haInterval=5000] The High availability period for replicaset inquiry | ||
* @param {boolean} [options.emitError=false] Server will emit errors events | ||
* @param {Cursor} [options.cursorFactory=Cursor] The cursor factory class used for all query cursors | ||
* @param {string} options.host The server host | ||
* @param {number} options.port The server port | ||
* @param {number} [options.size=5] Server connection pool size | ||
@@ -192,3 +209,3 @@ * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled | ||
var reconnectTries = options.reconnectTries || 30; | ||
var haInterval = options.haInterval || 2000; | ||
var haInterval = options.haInterval || 5000; | ||
// Set up the connection timeout for the options | ||
@@ -659,4 +676,4 @@ options.connectionTimeout = options.connectionTimeout || 1000; | ||
* @param {object} cmd The command hash | ||
* @param {object} [options.readPreference] Specify read preference if command supports it | ||
* @param {object} [options.connection] Specify connection object to execute command against | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @param {Connection} [options.connection] Specify connection object to execute command against | ||
* @param {opResultCallback} callback A callback function | ||
@@ -750,7 +767,3 @@ */ | ||
* @param {array} [options.documents=[]] Initial documents list for cursor | ||
* @param {boolean} [options.tailable=false] Tailable flag set | ||
* @param {boolean} [options.oplogReply=false] oplogReply flag set | ||
* @param {boolean} [options.awaitdata=false] awaitdata flag set | ||
* @param {boolean} [options.exhaust=false] exhaust flag set | ||
* @param {boolean} [options.partial=false] partial flag set | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @param {opResultCallback} callback A callback function | ||
@@ -760,3 +773,3 @@ */ | ||
cursorOptions = cursorOptions || {}; | ||
var FinalCursor = cursorOptions.cursorFactory || Cursor; | ||
var FinalCursor = cursorOptions.cursorFactory || BasicCursor; | ||
return new FinalCursor(bson, ns, cmd, cursorOptions, self, options); | ||
@@ -837,3 +850,3 @@ } | ||
* @method | ||
* @param {object} [options.readPreference={}] Read preference for the connection | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @return {Connection} | ||
@@ -854,3 +867,3 @@ */ | ||
* @method | ||
* @param {object} [options.readPreference={}] Read preference for the connection | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @return {Server} | ||
@@ -868,3 +881,3 @@ */ | ||
* @method | ||
* @return {array} | ||
* @return {Connection[]} | ||
*/ | ||
@@ -871,0 +884,0 @@ this.connections = function() { |
@@ -6,2 +6,26 @@ var getSingleProperty = require('../connection/utils').getSingleProperty; | ||
/** | ||
* @fileOverview The **ReadPreference** class is a class that represents a MongoDB ReadPreference and is | ||
* used to construct connections. | ||
* | ||
* @example | ||
* var ReplSet = require('mongodb-core').ReplSet | ||
* , ReadPreference = require('mongodb-core').ReadPreference | ||
* , assert = require('assert'); | ||
* | ||
* var server = new ReplSet([{host: 'localhost', port: 30000}], {setName: 'rs'}); | ||
* // Wait for the connection event | ||
* server.on('connect', function(server) { | ||
* var cursor = server.cursor('db.test' | ||
* , {find: 'db.test', query: {}} | ||
* , {readPreference: new ReadPreference('secondary')}); | ||
* cursor.next(function(err, doc) { | ||
* server.destroy(); | ||
* }); | ||
* }); | ||
* | ||
* // Start connecting | ||
* server.connect(); | ||
*/ | ||
/** | ||
* Creates a new Pool instance | ||
@@ -8,0 +32,0 @@ * @class |
@@ -11,3 +11,3 @@ var inherits = require('util').inherits | ||
, Session = require('./session') | ||
, Cursor = require('../cursor') | ||
, BasicCursor = require('../cursor') | ||
, BSON = require('bson').native().BSON | ||
@@ -17,2 +17,21 @@ , State = require('./replset_state') | ||
/** | ||
* @fileOverview The **ReplSet** class is a class that represents a Replicaset topology and is | ||
* used to construct connections. | ||
* | ||
* @example | ||
* var ReplSet = require('mongodb-core').ReplSet | ||
* , ReadPreference = require('mongodb-core').ReadPreference | ||
* , assert = require('assert'); | ||
* | ||
* var server = new ReplSet([{host: 'localhost', port: 30000}], {setName: 'rs'}); | ||
* // Wait for the connection event | ||
* server.on('connect', function(server) { | ||
* server.destroy(); | ||
* }); | ||
* | ||
* // Start connecting | ||
* server.connect(); | ||
*/ | ||
var DISCONNECTED = 'disconnected'; | ||
@@ -51,4 +70,2 @@ var CONNECTING = 'connecting'; | ||
* @param {Cursor} [options.cursorFactory=Cursor] The cursor factory class used for all query cursors | ||
* @param {string} options.host The server host | ||
* @param {number} options.port The server port | ||
* @param {number} [options.size=5] Server connection pool size | ||
@@ -97,3 +114,3 @@ * @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled | ||
// | ||
var Cursor = options.cursorFactory || Cursor; | ||
var Cursor = options.cursorFactory || BasicCursor; | ||
@@ -345,34 +362,5 @@ // BSON Parser, ensure we have a single instance | ||
// console.log("------------------------------------------------ HA 0") | ||
// Update the replicaset state | ||
replState.update(ismaster, server); | ||
// console.log("------------------------------------------------ HA 1") | ||
// // Let's check what kind of server this is | ||
// if(ismaster.ismaster && setName == ismaster.setName | ||
// && !replState.isPrimary(ismaster.me)) { | ||
// if(logger.isInfo()) logger.info(f('[%s] promoting %s to primary', id, ismaster.me)); | ||
// replState.promotePrimary(server); | ||
// self.emit('reconnect', server); | ||
// self.emit('joined', 'primary', server); | ||
// } else if(ismaster.secondary && ismaster.passive && setName == ismaster.setName | ||
// && !replState.isPassive(ismaster.me)) { | ||
// if(logger.isInfo()) logger.info(f('[%s] promoting %s to secondary', id, ismaster.me)); | ||
// replState.addPassive(server); | ||
// self.emit('joined', 'passive', server); | ||
// } else if(ismaster.secondary && setName == ismaster.setName | ||
// && !replState.isSecondary(ismaster.me)) { | ||
// if(logger.isInfo()) logger.info(f('[%s] promoting %s to secondary', id, ismaster.me)); | ||
// replState.addSecondary(server); | ||
// self.emit('joined', 'secondary', server); | ||
// } else if(ismaster.arbiterOnly && setName == ismaster.setName) { | ||
// if(logger.isInfo()) logger.info(f('[%s] promoting %s to ariter', id, ismaster.me)); | ||
// replState.addArbiter(server); | ||
// self.emit('joined', 'arbiter', server); | ||
// } else if(!ismaster.ismaster && !ismaster.secondary && !ismaster.arbiterOnly) { | ||
// if(logger.isInfo()) logger.info(f('[%s] removing %s from set', id, ismaster.me)); | ||
// replState.remove(server); | ||
// self.emit('left', 'secondary', server); | ||
// } | ||
// Add any new servers | ||
@@ -760,4 +748,4 @@ if(err == null && ismaster.ismaster && Array.isArray(ismaster.hosts)) { | ||
* @param {object} cmd The command hash | ||
* @param {object} [options.readPreference] Specify read preference if command supports it | ||
* @param {object} [options.connection] Specify connection object to execute command against | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @param {Connection} [options.connection] Specify connection object to execute command against | ||
* @param {opResultCallback} callback A callback function | ||
@@ -948,7 +936,3 @@ */ | ||
* @param {array} [options.documents=[]] Initial documents list for cursor | ||
* @param {boolean} [options.tailable=false] Tailable flag set | ||
* @param {boolean} [options.oplogReply=false] oplogReply flag set | ||
* @param {boolean} [options.awaitdata=false] awaitdata flag set | ||
* @param {boolean} [options.exhaust=false] exhaust flag set | ||
* @param {boolean} [options.partial=false] partial flag set | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @param {opResultCallback} callback A callback function | ||
@@ -958,3 +942,3 @@ */ | ||
cursorOptions = cursorOptions || {}; | ||
var FinalCursor = cursorOptions.cursorFactory || Cursor; | ||
var FinalCursor = cursorOptions.cursorFactory || BasicCursor; | ||
return new FinalCursor(bson, ns, cmd, cursorOptions, self, options); | ||
@@ -1069,3 +1053,3 @@ } | ||
* @method | ||
* @param {object} [options.readPreference={}] Read preference for the connection | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @return {Connection} | ||
@@ -1086,3 +1070,3 @@ */ | ||
* @method | ||
* @param {object} [options.readPreference={}] Read preference for the connection | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @return {Server} | ||
@@ -1100,3 +1084,3 @@ */ | ||
* @method | ||
* @return {array} | ||
* @return {Connection[]} | ||
*/ | ||
@@ -1103,0 +1087,0 @@ this.connections = function() { |
@@ -26,2 +26,21 @@ var inherits = require('util').inherits | ||
/** | ||
* @fileOverview The **Server** class is a class that represents a single server topology and is | ||
* used to construct connections. | ||
* | ||
* @example | ||
* var Server = require('mongodb-core').Server | ||
* , ReadPreference = require('mongodb-core').ReadPreference | ||
* , assert = require('assert'); | ||
* | ||
* var server = new Server({host: 'localhost', port: 27017}); | ||
* // Wait for the connection event | ||
* server.on('connect', function(server) { | ||
* server.destroy(); | ||
* }); | ||
* | ||
* // Start connecting | ||
* server.connect(); | ||
*/ | ||
// All bson types | ||
@@ -552,4 +571,4 @@ var bsonTypes = [b.Long, b.ObjectID, b.Binary, b.Code, b.DBRef, b.Symbol, b.Double, b.Timestamp, b.MaxKey, b.MinKey]; | ||
* @param {object} cmd The command hash | ||
* @param {object} [options.readPreference] Specify read preference if command supports it | ||
* @param {object} [options.connection] Specify connection object to execute command against | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @param {Connection} [options.connection] Specify connection object to execute command against | ||
* @param {opResultCallback} callback A callback function | ||
@@ -842,3 +861,3 @@ */ | ||
* @method | ||
* @return {array} | ||
* @return {Connection[]} | ||
*/ | ||
@@ -852,3 +871,3 @@ this.connections = function() { | ||
* @method | ||
* @param {object} [options.readPreference={}] Read preference for the connection | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @return {Server} | ||
@@ -872,3 +891,3 @@ */ | ||
* @method | ||
* @param {object} [options.readPreference={}] Read preference for the connection | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @return {Connection} | ||
@@ -913,3 +932,3 @@ */ | ||
// , tailable: <boolean> | ||
// , oplogReply: <boolean> | ||
// , oplogReplay: <boolean> | ||
// , noCursorTimeout: <boolean> | ||
@@ -928,2 +947,3 @@ // , awaitdata: <boolean> | ||
* @param {array} [options.documents=[]] Initial documents list for cursor | ||
* @param {ReadPreference} [options.readPreference] Specify read preference if command supports it | ||
* @param {opResultCallback} callback A callback function | ||
@@ -933,3 +953,3 @@ */ | ||
cursorOptions = cursorOptions || {}; | ||
var FinalCursor = cursorOptions.cursorFactory || Cursor; | ||
var FinalCursor = cursorOptions.cursorFactory || BasicCursor; | ||
return new FinalCursor(bson, ns, cmd, cursorOptions, self, options); | ||
@@ -936,0 +956,0 @@ } |
@@ -454,3 +454,3 @@ var Insert = require('./commands').Insert | ||
if(typeof cmd.tailable == 'boolean') query.tailable = cmd.tailable; | ||
if(typeof cmd.oplogReply == 'boolean') query.oplogReply = cmd.oplogReply; | ||
if(typeof cmd.oplogReplay == 'boolean') query.oplogReplay = cmd.oplogReplay; | ||
if(typeof cmd.noCursorTimeout == 'boolean') query.noCursorTimeout = cmd.noCursorTimeout; | ||
@@ -503,3 +503,3 @@ if(typeof cmd.awaitData == 'boolean') query.awaitData = cmd.awaitData; | ||
if(options.tailable) query.tailable = options.tailable; | ||
if(options.oplogReply)query.oplogReply = options.oplogReply; | ||
if(options.oplogReplay)query.oplogReplay = options.oplogReplay; | ||
if(options.noCursorTimeout) query.noCursorTimeout = options.noCursorTimeout; | ||
@@ -506,0 +506,0 @@ if(options.awaitdata) query.awaitdata = options.awaitdata; |
@@ -192,3 +192,3 @@ var Insert = require('./commands').Insert | ||
if(typeof cmd.tailable == 'boolean') query.tailable = cmd.tailable; | ||
if(typeof cmd.oplogReply == 'boolean') query.oplogReply = cmd.oplogReply; | ||
if(typeof cmd.oplogReplay == 'boolean') query.oplogReplay = cmd.oplogReplay; | ||
if(typeof cmd.noCursorTimeout == 'boolean') query.noCursorTimeout = cmd.noCursorTimeout; | ||
@@ -241,3 +241,3 @@ if(typeof cmd.awaitData == 'boolean') query.awaitData = cmd.awaitData; | ||
if(typeof options.tailable == 'boolean') query.tailable = options.tailable; | ||
if(typeof options.oplogReply == 'boolean') query.oplogReply = options.oplogReply; | ||
if(typeof options.oplogReplay == 'boolean') query.oplogReplay = options.oplogReplay; | ||
if(typeof options.noCursorTimeout == 'boolean') query.noCursorTimeout = options.noCursorTimeout; | ||
@@ -244,0 +244,0 @@ if(typeof options.awaitdata == 'boolean') query.awaitdata = options.awaitdata; |
{ | ||
"name": "mongodb-core", | ||
"version": "1.0.0-alpha9", | ||
"version": "1.0.0", | ||
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
227
README.md
@@ -1,4 +0,225 @@ | ||
mongodb-core | ||
============ | ||
# Description | ||
MongoDB core driver functionality aims to make the "smallest" viable driver api | ||
The MongoDB Core driver is the low level part of the 2.0 or higher MongoDB driver and is meant for library developers not end users. It does not contain any abstractions or helpers outside of the basic management of MongoDB topology connections, CRUD operations and authentication. | ||
## MongoDB Node.JS Core Driver | ||
| what | where | | ||
|---------------|------------------------------------------------| | ||
| documentation | http://mongodb.github.io/node-mongodb-native/ | | ||
| apidoc | http://mongodb.github.io/node-mongodb-native/ | | ||
| source | https://github.com/christkv/mongodb-core | | ||
| mongodb | http://www.mongodb.org/ | | ||
### Blogs of Engineers involved in the driver | ||
- Christian Kvalheim [@christkv](https://twitter.com/christkv) <http://christiankvalheim.com> | ||
### Bugs / Feature Requests | ||
Think you’ve found a bug? Want to see a new feature in node-mongodb-native? Please open a | ||
case in our issue management tool, JIRA: | ||
- Create an account and login <https://jira.mongodb.org>. | ||
- Navigate to the NODE project <https://jira.mongodb.org/browse/NODE>. | ||
- Click **Create Issue** - Please provide as much information as possible about the issue type and how to reproduce it. | ||
Bug reports in JIRA for all driver projects (i.e. NODE, PYTHON, CSHARP, JAVA) and the | ||
Core Server (i.e. SERVER) project are **public**. | ||
### Questions and Bug Reports | ||
* mailing list: https://groups.google.com/forum/#!forum/node-mongodb-native | ||
* jira: http://jira.mongodb.org/ | ||
### Change Log | ||
http://jira.mongodb.org/browse/NODE | ||
# QuickStart | ||
The quick start guide will show you how to set up a simple application using Core driver and MongoDB. It scope is only how to set up the driver and perform the simple crud operations. For more inn depth coverage we encourage reading the tutorials. | ||
## Create the package.json file | ||
Let's create a directory where our application will live. In our case we will put this under our projects directory. | ||
``` | ||
mkdir myproject | ||
cd myproject | ||
``` | ||
Create a **package.json** using your favorite text editor and fill it in. | ||
```json | ||
{ | ||
"name": "myproject", | ||
"version": "1.0.0", | ||
"description": "My first project", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/christkv/myfirstproject.git" | ||
}, | ||
"dependencies": { | ||
"mongodb-core": "~1.0" | ||
}, | ||
"author": "Christian Kvalheim", | ||
"license": "Apache 2.0", | ||
"bugs": { | ||
"url": "https://github.com/christkv/myfirstproject/issues" | ||
}, | ||
"homepage": "https://github.com/christkv/myfirstproject" | ||
} | ||
``` | ||
Save the file and return to the shell or command prompt and use **NPM** to install all the dependencies. | ||
``` | ||
npm install | ||
``` | ||
You should see **NPM** download a lot of files. Once it's done you'll find all the downloaded packages under the **node_modules** directory. | ||
Booting up a MongoDB Server | ||
--------------------------- | ||
Let's boot up a MongoDB server instance. Download the right MongoDB version from [MongoDB](http://www.mongodb.org), open a new shell or command line and ensure the **mongod** command is in the shell or command line path. Now let's create a database directory (in our case under **/data**). | ||
``` | ||
mongod --dbpath=/data --port 27017 | ||
``` | ||
You should see the **mongod** process start up and print some status information. | ||
## Connecting to MongoDB | ||
Let's create a new **app.js** file that we will use to show the basic CRUD operations using the MongoDB driver. | ||
First let's add code to connect to the server. Notice that there is no concept of a database here and we use the topology directly to perform the connection. | ||
```js | ||
var Server = require('mongodb-core').Server | ||
, assert = require('assert'); | ||
// Set up server connection | ||
var server = new Server({ | ||
host: 'localhost' | ||
, port: 27017 | ||
, reconnect: true | ||
, reconnectInterval: 50 | ||
}); | ||
// Add event listeners | ||
server.on('connect', function(_server) { | ||
console.log('connected'); | ||
test.done(); | ||
}); | ||
server.on('close', function() { | ||
console.log('closed'); | ||
}); | ||
server.on('reconnect', function() { | ||
console.log('reconnect'); | ||
}); | ||
// Start connection | ||
server.connect(); | ||
``` | ||
To connect to a replicaset we would use the `ReplSet` class and for a set of Mongos proxies we use the `Mongos` class. Each topology class offer the same CRUD operations and you operate on the topology directly. Let's look at an example exercising all the different available CRUD operations. | ||
```js | ||
var Server = require('mongodb-core').Server | ||
, assert = require('assert'); | ||
// Set up server connection | ||
var server = new Server({ | ||
host: 'localhost' | ||
, port: 27017 | ||
, reconnect: true | ||
, reconnectInterval: 50 | ||
}); | ||
// Add event listeners | ||
server.on('connect', function(_server) { | ||
console.log('connected'); | ||
// Execute the ismaster command | ||
_server.command('system.$cmd', {ismaster: true}, function(err, result) { | ||
// Perform a document insert | ||
_server.insert('myproject.inserts1', [{a:1}, {a:2}], { | ||
writeConcern: {w:1}, ordered:true | ||
}, function(err, results) { | ||
assert.equal(null, err); | ||
assert.equal(2, results.result.n); | ||
// Perform a document update | ||
_server.update('myproject.inserts1', [{ | ||
q: {a: 1}, u: {'$set': {b:1}} | ||
}], { | ||
writeConcern: {w:1}, ordered:true | ||
}, function(err, results) { | ||
assert.equal(null, err); | ||
assert.equal(1, results.result.n); | ||
// Remove a document | ||
_server.remove('myproject.inserts1', [{ | ||
q: {a: 1}, limit: 1 | ||
}], { | ||
writeConcern: {w:1}, ordered:true | ||
}, function(err, results) { | ||
assert.equal(null, err); | ||
assert.equal(1, results.result.n); | ||
// Get a document | ||
var cursor = _server.cursor('integration_tests.inserts_example4', { | ||
find: 'integration_tests.example4' | ||
, query: {a:1} | ||
}); | ||
// Get the first document | ||
cursor.next(function(err, doc) { | ||
assert.equal(null, err); | ||
assert.equal(2, doc.a); | ||
// Execute the ismaster command | ||
_server.command("system.$cmd" | ||
, {ismaster: true}, function(err, result) { | ||
assert.equal(null, err) | ||
_server.destroy(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
test.done(); | ||
}); | ||
}); | ||
server.on('close', function() { | ||
console.log('closed'); | ||
}); | ||
server.on('reconnect', function() { | ||
console.log('reconnect'); | ||
}); | ||
// Start connection | ||
server.connect(); | ||
``` | ||
The core driver does not contain any helpers or abstractions only the core crud operations. These consist of the following commands. | ||
* `insert`, Insert takes an array of 1 or more documents to be inserted against the topology and allows you to specify a write concern and if you wish to execute the inserts in order or out of order. | ||
* `update`, Update takes an array of 1 or more update commands to be executed against the server topology and also allows you to specify a write concern and if you wish to execute the updates in order or out of order. | ||
* `remove`, Remove takes an array of 1 or more remove commands to be executed against the server topology and also allows you to specify a write concern and if you wish to execute the removes in order or out of order. | ||
* `cursor`, Returns you a cursor for either the 'virtual' `find` command, a command that returns a cursor id or a plain cursor id. Read the cursor tutorial for more inn depth coverage. | ||
* `command`, Executes a command against MongoDB and returns the result. | ||
* `auth`, Authenticates the current topology using a supported authentication scheme. | ||
The Core Driver is a building block for library builders and is not meant for usage by end users as it lacks a lot of features the end user might need such as automatic buffering of operations when a primary is changing in a replicaset or the db and collections abstraction. | ||
## Next steps | ||
The next steps is to get more inn depth information about how the different aspects of the core driver works and how to leverage them to extend the functionality of the cursors. Please view the tutorials for more detailed information. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
336407
37
8627
1
226