mongodb-data-service
MongoDB Data Service
The data service provides an API on top of [currently] the MongoDB Node Driver and
[in the future] mongodb-scout-client.
Installation
npm install --save mongodb-data-service
Usage
Instantiating the service.
const Connection = require('mongodb-connection-model');
const DataService = require('mongodb-data-service');
var model = new Connection({ hostname: '127.0.0.1', port: 27018, ns: 'data-service' });
var service = new DataService(model);
Connecting to the server.
Once the service is ready, it will also emit a DataService.Events.Readble
event.
service.connect((error) => {
assert.equal(null, error);
});
function handleReadable() {
console.log('Connected!');
}
service.on(DataService.Events.Readable, handleReadable);
API
service.collection('database.collection', {}, (error, result) => {
assert.equal(null, error);
});
service.count('database.collection', { a: 1 }, {}, (error, count) => {
assert.equal(null, error);
});
service.database('database', {}, (error, result) => {
assert.equal(null, error);
});
service.find('database.collection', { a: 1 }, {}, (error, documents) => {
assert.equal(null, error);
});
service.get('/collection/database.test', {}, (error, result) => {
assert.equal(null, error);
});
service.instance({}, (error, result) => {
assert.equal(null, error);
});
service.sample('database.collection', {});
License
Apache 2.0