npm

Need private packages and team management tools?Check out npm Orgs. »

mongodb-data-service

15.3.1 • Public • Published

mongodb-data-service

MongoDB Data Service: an API on top of (currently) the MongoDB Node Driver and (some day) mongodb-scope-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 service = new DataService(new Connection({
  hostname: '127.0.0.1',
  port: 27018,
  ns: 'data-service'
}));

Connecting to the server.

Once the service is ready, it will also emit a readable event.

service.connect((err) => assert.equal(null, err)})
  .on('readable', () => console.log('Connected!'));

API

// Get information for a collection.
service.collection('database.collection', {}, (error, result) => {
  assert.equal(null, error);
});
 
// Get a document count.
service.count('database.collection', { a: 1 }, {}, (error, count) => {
  assert.equal(null, error);
});
 
// Get information for a database.
service.database('database', {}, (error, result) => {
  assert.equal(null, error);
});
 
// Find documents in a collection.
service.find('database.collection', { a: 1 }, {}, (error, documents) => {
  assert.equal(null, error);
});
 
// Get a result for a RESTful endpoint.
service.get('/collection/database.test', {}, (error, result) => {
  assert.equal(null, error);
});
 
// Get instance details.
service.instance({}, (error, result) => {
  assert.equal(null, error);
});
 
// Get a sample stream of documents from a collection.
service.sample('database.collection', {});

Instance Details

collections

[
  {
    _id: 'admin.system.version',
    name: 'system.version',
    database: 'admin',
    readonly: false,
    collation: null,
    type: 'collection',
    view_on: undefined,
    pipeline: undefined
  },
  {
    _id: 'config.system.sessions',
    name: 'system.sessions',
    database: 'config',
    readonly: false,
    collation: null,
    type: 'collection',
    view_on: undefined,
    pipeline: undefined
  },
  {
    _id: 'data-service.test',
    name: 'test',
    database: 'data-service',
    readonly: false,
    collation: null,
    type: 'collection',
    view_on: undefined,
    pipeline: undefined
  },
  {
    _id: 'data-service.system.views',
    name: 'system.views',
    database: 'data-service',
    readonly: false,
    collation: null,
    type: 'collection',
    view_on: undefined,
    pipeline: undefined
  },
  {
    _id: 'data-service.myView',
    name: 'myView',
    database: 'data-service',
    readonly: true,
    collation: null,
    type: 'view',
    view_on: 'test',
    pipeline: [{ $project: { a: 0 } }]
  },
  {
    _id: 'local.startup_log',
    name: 'startup_log',
    database: 'local',
    readonly: false,
    collation: null,
    type: 'collection',
    view_on: undefined,
    pipeline: undefined
  }
]

License

Apache 2.0

Keywords

install

npm i mongodb-data-service

Downloadsweekly downloads

72

version

15.3.1

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability