mongoscope-client
Version:
314 lines (182 loc) • 7.95 kB
Markdown
# mongoscope-client
[](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)

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)

List all deployments this mongoscope instance has connected to.
#### Parameters
- `fn` (required, Function) ... Called when the request is complete `(err, data)`
### mongoscope.sharding(fn)

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)

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)

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)

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)

A structured view of the ramlog.
#### Parameters
- `fn` (optional, Function) ... Called when the request is complete `(err, data)`
### mongoscope.database(name, fn)

List collection names and stats.
#### Parameters
- `name` (required, String)
- `fn` (required, Function) ... Called when the request is complete `(err, data)`
### mongoscope.collection(ns, fn)

Collection stats
#### Parameters
- `ns` (required, String)
- `fn` (required, Function) ... Called when the request is complete `(err, data)`
### mongoscope.ops(fn)

List currently running operations.
#### Parameters
- `fn` (optional, Function) ... Called when the request is complete `(err, data)`
### mongoscope.destroyOp(opId, fn)

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)

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)

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)

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)

Run a count on `db.collection`.
#### Parameters
- `ns` (required, String)
- `opts` (required, Object)
- `fn` (required, Function)
### mongoscope.aggregate(ns, pipeline, opts, fn)

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)

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)

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)

Working set size estimator.
#### Parameters
- `fn` (required, Function) ... Called when the request is complete `(err, data)`
### mongoscope.get(fragment, params, fn)

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

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)

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)`