Index

lib/cursor.js

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();

lib/topologies/mongos.js

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();

lib/topologies/read_preference.js

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();

comments powered by Disqus