UNPKG

mongoscope-client

Version:
314 lines (182 loc) 7.95 kB
# mongoscope-client [![build status](https://secure.travis-ci.org/imlucas/mongoscope-client.png)](http://travis-ci.org/imlucas/mongoscope-client) A client for wielding [mongoscope](http:github.com/10gen/mongoscope) like the hammer of thor. [Codepen Collection of Examples](http://codepen.io/collection/Gdeok/) ``` npm install --save mongoscope-client ``` ## API ```javascript var mongoscope = require('mongoscope-client')(); ``` ### Configuration ```javascript var mongoscope = require('mongoscope-client')(opts); ``` #### Parameters - `opts` (optional, Object) - `scope` = `http://localhost:29017` (optional, String) ... Where mongoscope-server is running - `seed` = `localhost:27017` (optional, String) ... MongoDB instance hostport string to default connections to. *Note:* DNS is relative to mongoscope-server! ### mongoscope.instance(fn) ![production](http://b.repl.ca/v1/stability-production-green.png) Get details of the instance you're currently connected to like database_names, results of the hostInfo and buildInfo mongo commands. #### Parameters - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.deployments(fn) ![production](http://b.repl.ca/v1/stability-production-green.png) List all deployments this mongoscope instance has connected to. #### Parameters - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.sharding(fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) Get the sharding info for the cluster the instance you're connected to is a member of, similar to the `printShardingStatus()` helper function in the mongo shell. #### Examples - [Sharding Report](http://codepen.io/imlucas/pen/JgzAh) #### Parameters - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.replication(fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) View current state of all members and oplog details. #### Parameters - `fn` (optional, Function) ... Called when the request is complete `(err, data)` ### mongoscope.oplog(opts, fn) ![prototype](http://b.repl.ca/v1/stability-prototype-orange.png) Get oplog entries. #### Parameters - `opts` (optional, Object) ... - `since` (Number) - `filters` (Array) - `fn` (optional, Function) ... Called when the request is complete `(err, data)` ### mongoscope.top(opts, fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) Capture the deltas of top over `opts.interval` ms. #### Parameters - `opts` (optional, Object) ... - `interval` (Number) - `fn` (optional, Function) ... Called when the request is complete `(err, data)` ### mongoscope.log(fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) A structured view of the ramlog. #### Parameters - `fn` (optional, Function) ... Called when the request is complete `(err, data)` ### mongoscope.database(name, fn) ![production](http://b.repl.ca/v1/stability-production-green.png) List collection names and stats. #### Parameters - `name` (required, String) - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.collection(ns, fn) ![production](http://b.repl.ca/v1/stability-production-green.png) Collection stats #### Parameters - `ns` (required, String) - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.ops(fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) List currently running operations. #### Parameters - `fn` (optional, Function) ... Called when the request is complete `(err, data)` ### mongoscope.destroyOp(opId, fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) Kill a currently running operation. #### Parameters - `opId` (required, Number) - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.index(ns, name, fn) ![prototype](http://b.repl.ca/v1/stability-prototype-orange.png) Index details #### Parameters - `ns` (required, String) - `name` (required, String) ... The index name - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.document(ns, _id, fn) ![prototype](http://b.repl.ca/v1/stability-prototype-orange.png) Get a document #### Parameters - `ns` (required, String) - `_id` (required, String) - `fn` (required, Function) ... Called when the request is complete `(err, data)` #### Todo - [ ] Need to get extended JSON support sorted before moving forward. ### mongoscope.find(ns, opts, fn) ![production](http://b.repl.ca/v1/stability-production-green.png) Run a query on `db.collection`. #### Parameters - `ns` (required, String) - `opts` (optional, Object) ... - `query` (Object) - `limit` (Number) - `skip` (Number) - `explain` (Boolean) - `sort` (Object) - `fields` (Object) - `options` (Object) - `batchSize` (Number) - `fn` (optional, Function) ... Called when the request is complete `(err, data)` ### mongoscope.count(ns, opts, fn) ![production](http://b.repl.ca/v1/stability-production-green.png) Run a count on `db.collection`. #### Parameters - `ns` (required, String) - `opts` (required, Object) - `fn` (required, Function) ### mongoscope.aggregate(ns, pipeline, opts, fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) Run an aggregation pipeline on `db.collection`. #### Examples - [Run an aggregation and chart it](http://codepen.io/imlucas/pen/BHvLE) #### Parameters - `ns` (required, String) - `pipeline` (required, Array) - `opts` (required, Object) - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.sample(fn) undefined Use [resevoir sampling](http://en.wikipedia.org/wiki/Reservoir_sampling) to get a slice of documents from a collection efficiently. #### Parameters - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.random(ns, opts, fn) ![prototype](http://b.repl.ca/v1/stability-prototype-orange.png) Convenience to get 1 document via `Client.prototype.sample`. #### Parameters - `ns` (required, String) - `opts` (required, Object) - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.analytics(group, fn) ![prototype](http://b.repl.ca/v1/stability-prototype-orange.png) Get or stream a group of analytics. #### Parameters - `group` (required, String) ... One of `Client.prototype.analytics.groups` - `fn` (optional, Function) ... Called when the request is complete `(err, data)` ### mongoscope.workingSet(fn) ![prototype](http://b.repl.ca/v1/stability-prototype-orange.png) Working set size estimator. #### Parameters - `fn` (required, Function) ... Called when the request is complete `(err, data)` ### mongoscope.get(fragment, params, fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) Route `fragment` to a call on `Client.prototype`, which is substantially easier for users on the client-side. More detailled usage is available in the [backbone.js adapter](/lib/backbone.js). #### Parameters - `fragment` (required, String) ... One of `Client.prototype.routes` - `params` (optional, Object) - `fn` (optional, Function) ### mongoscope.backbone ![production](http://b.repl.ca/v1/stability-production-green.png) Get an instance of the backbone adapter bound to this client instance. #### Examples - [Backbone.js adapter](http://codepen.io/imlucas/pen/Ltigv) ### mongoscope.connect(seed, fn) ![development](http://b.repl.ca/v1/stability-development-yellow.png) Point at a difference instance, only replacing the token object so all of your event listeners remain intact. #### Parameters - `seed` (required, String) - `fn` (required, Function) ... Called when the request is complete `(err, data)`