1.0.3 • Published 10 years ago

objectrocket v1.0.3

Weekly downloads
58
License
-
Repository
github
Last release
10 years ago

Object Rocket API calls documentation

objectrocket

The ObjectRocket API is a REST based HTTP API. The API can be used in addition to and along side the MongoDB driver to access an ObjectRocket instance. The API expects a HTTP POST with a document and an API key. The document can be the document to write to the database, or it can be a query object in the form of the query’s predicate. The following Node.js examples are written in Node.js v0.8.14 to showcase the uses of the built in objectrocket node module for calling the remote ObjectRocket API.

Install

$ npm install objectrocket

APIs

Import the objectrocket node module

var objectrocket = require('objectrocket');

Add

The Add API operation inserts a document into the given collection (collection) in the given database (db). If the insert is successful, the object is returned with a primary key (_id). The following are the details to call the Add API for inserting the document :

objectrocket.add(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • document : The JSON document that you are adding to the given collection. Example : {"first_name":"Chuck", "last_name":"Smith"}.
  • db : The name of the database that contains the collection that you are inserting the document into.
  • collection : The name of the collection or table that you are inserting the document into.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"first_name":"Chuck", "last_name":"Smith"},
  "db" : "mydb0",
  "collection" : "mycol0"
}
objectrocket.add(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "first_name": "Chuck",
    "last_name": "Smith",
    "_id": {
      "$oid": "50876f83cb72593131000000"
    }
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Get

The Get API operation returns a set of the document(s) that meet the given document query (document) from the given collection (collection) in the given database (db). The following are the details to call the Get API for retrieving the set of document(s) :

objectrocket.get_data(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • document : The JSON document that you are retrieving from the given collection. Example : {"first_name":"Chuck", "last_name":"Smith"}.
  • db : The name of the database that contains the collection that you are retrieving the documents from.
  • collection : The name of the collection or table that you are retrieving the documents from.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"first_name":"Chuck", "last_name":"Smith"},
  "db" : "mydb0",
  "collection" : "mycol0"
}
objectrocket.get_data(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": [
    {
      "last_name": "Smith",
      "first_name": "Chuck",
      "_id": {
        "$oid": "50876f83cb72593131000000"
      },
    }
  ],
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Update

The Update API operation will update the first document in the given collection (collection) in the given database (db) that matches the given query predicate (document) and set all of that document’s values to that which are specified in the set (new_document) clause. Fields that are omitted in the set operation will be removed from the updated document. If successful, the returned data will specify the number of affected documents. The following are the details to call the Update API for updating the document :

objectrocket.update(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • document : The document predicate in the form of a JSON. Example : {"first_name":"Chuck", "last_name":"Smith"}.
  • new_document : The JSON document that will replace the first instance of the document that meets the query predicate. Example : {"first_name":"Chuck", "last_name":"Smith"}.
  • db : The name of the database that contains the collection that you are updating the document in.
  • collection : The name of the collection or table that you are updating the document in.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"first_name":"Chuck", "last_name":"Smith"},
  "new_document" : {"first_name":"Chuck", "last_name":"Smith"},
  "db" : "mydb0",
  "collection" : "mycol0"
}
objectrocket.update(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "rc": 0,
  "n": 1
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Delete

The Delete API operation deletes all documents in the given collection (collection) in the given database (db) that meet the criteria specified in the query predicate (document). If successful, the returned data specifies the number of deleted documents. The following are the details for calling the Delete API to delete the document :

objectrocket.delete_data(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • document : The document predicate in the form of a JSON. Example : {"first_name":"Chuck", "last_name":"Smith"}.
  • db : The name of the database that contains the collection that you are deleting the document from.
  • collection : The name of the collection or table that you are deleting the document from.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"first_name":"Chuck", "last_name":"Smith"},
  "db" : "mydb0",
  "collection" : "mycol0"
}
objectrocket.delete_data(JSON.stringify(options), function(error, result) {
    // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "rc": 0,
  "n": 4
}

In case of error :

{
  rc: 1,
  msg: error_message
}

MongoDB Instance Management Operations

Instance Details

The Instance Details API operation returns details about all ObjectRocket instances associated with the given API key (api_key). The following are the details for calling the Instance Details API to get the details of the instance :

objectrocket.instance(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.instance(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "name": "rocketdemo",
    "zone": "US-West",
    "host": "w-mongos0.objectrocket.com",
    "plan": 20,
    "port": 10013,
    "size": 20.0
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Server Status

The Server Status API operation returns an object of type ServerStatus showing counters for various operations for the instances of the given API key (api_key). The output returned by the Server Status API operation is required by the rocketstat utility. The following are the details for calling the Server Status API :

objectrocket.serverstatus(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.serverstatus(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "indexCounters": {
      "btree": {
          "missRatio": 0.0,
          "resets": 0,
          "hits": 1884749,
          "misses": 0,
          "accesses": 1884749
      }
    },
    "connections": {
      "current": 31,
      "available": 19969
    },
    "plan": 20,
    "cursors": {
      "clientCursors_size": 2,
      "timedOut": 33,
      "totalOpen": 2
    },
  }
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Space Usage

The Space Usage API operation returns a summary of disk space usage in bytes for each of the ObjectRocket instances for the given API key (API_KEY). The following are the details for calling the Space Usage API :

objectrocket.spaceusage(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.spaceusage(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "total_size": 3502428160.0,
    "index_size": 2715159664.0,
    "shards": [
      {
        "total_size": 8734789488.0,
        "index_size": 2715037024.0,
        "file_size": 16283598848.0,
        "shard": "shard_30013",
        "data_size": 7130697772.0
      }
    ],
    "data_size": 2459198904.0,
    "file_size": 10917511168.0
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Add Database / Add User

The Add Database API operation will create a database with the given name (db) and given MongoDB user credentials (document: {"username":"password"}) for the given API key (api_key). If the database already exists, a user can be added to the database by using this operation. The following are the details for calling the Add Database / Add User API to create a database or adding the user to the database :

objectrocket.add_dbuser(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • db : The name of the database that will be created or if the database already exists, the name of the database that the given account will be granted access to.
  • document : The JSON document contains the username and password for the account that will be granted access to the given MongoDB database. Example : {"abc":"12345"}.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "db" : "mydb0",
  "docuemnt" : {"abc":"12345"}
}
objectrocket.add_dbuser(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": "OK",
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

List Databases

The List Databases API operation will return statistics about all databases owned by the given API key (api_key). The following are the details for calling the List Databases API :

objectrocket.listdb(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.listdb(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": [
    {
      "stats": {
          "dataSize": 328,
          "ok": 1.0,
          "avgObjSize": 46.857142857142854,
          "indexes": 1,
          "objects": 7,
          "fileSize": 50331648,
          "numExtents": 4,
          "storageSize": 1064960,
          "indexSize": 8176
      },
      "name": "mydb"
    },
    {
      "stats": {
          "dataSize": 448,
          "ok": 1.0,
          "avgObjSize": 64.0,
          "indexes": 1,
          "objects": 7,
          "fileSize": 50331648,
          "numExtents": 4,
          "storageSize": 1069056,
          "indexSize": 8176
      },
      "name": "mydb0"
    },
  ],
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Get Profiler Data

The Get Profiler Data API operation returns standard MongoDB profiler output for all the queries that meet the given criteria on all shards for the given API key. The following are the details for calling the Get Profiler Data API :

objectrocket.profiler(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • document : The document predicate in the form of a JSON. Example : {"millis": {"$gt":50}}.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"millis": {"$gt":50}}
}
objectrocket.profiler(JSON.stringify(options), function(error, result) {
    // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": [
    {
      "ns": "mydb0.mycol0",
      "millis": 54,
      "ts": {
        "$date": 1351058243597
      },
      "client": "10.48.2.30",
      "user": "",
      "query": {
        "first_name": "Chuck"
      },
      "updateobj": {
        "first_name": "Cornelius",
        "last_name": "Vanderbilt"
      },
      "nscanned": 1,
      "op": "update"
    }
  ],
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Server Status

Gets performance data for the instance, good for monitoring and management tools. The following are the details for calling the Server Status API :

objectrocket.serverstatus(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.serverstatus(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "indexCounters": { "btree": { "missRatio": 0.0, "resets": 0, "hits": 3333114, "misses": 0, "accesses": 3333114 }},
    "connections": { "current": 31, "available": 19969 },
    "plan": 20,
    "cursors": { "clientCursors_size": 2, "timedOut": 43, "totalOpen": 2 },
    "writeBacksQueued": false,
    "globalLock": {
      "totalTime": 3593490152795.0,
      "currentQueue": {
        "total": 0,
        "writers": 0,
        "readers": 0
      },
      "lockTime": 3742748320.0,
      "ratio": 0.001041535710648576,
      "activeClients": {
        "total": 2,
        "writers": 0,
        "readers": 2
      }
    },
    "backgroundFlushing": {
      "last_finished": {
        "$date": 1354911272239
      },
      "last_ms": 0,
      "flushes": 59891,
      "average_ms": 4.833196974503681,
      "total_ms": 289465
    },
    "opcounters": {
      "getmore": 9622259,
      "insert": 51991653,
      "update": 7388978,
      "command": 42125248,
      "query": 4085462,
      "delete": 40
    },
    "uptime": 3593490.0,
    "ok": 1.0,
    "network": { "numRequests": 111904374, "bytesOut": 23169121531.0, "bytesIn": 9693426113.0 },
    "zone": "US-West",
    "instance": "rocketdemo",
    "version": "2.0.6",
    "asserts": { "msg": 0, "rollovers": 0, "regular": 0, "warning": 12, "user": 297 }
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Server Status Plus

Identical to Server Status with an additional entry for greatest replication lag. The following are the details for calling the Server Status Plus API :

objectrocket.serverstatusplus(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.serverstatusplus(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "greatest_rep_lag": 0.2,
    "indexCounters": { "btree": { "missRatio": 0.0, "resets": 0, "hits": 3333114, "misses": 0, "accesses": 3333114 }},
    "connections": { "current": 31, "available": 19969 },
    "plan": 20,
    "cursors": { "clientCursors_size": 2, "timedOut": 43, "totalOpen": 2 },
    "writeBacksQueued": false,
    "globalLock": {
      "totalTime": 3593490152795.0,
      "currentQueue": {
        "total": 0,
        "writers": 0,
        "readers": 0
      },
      "lockTime": 3742748320.0,
      "ratio": 0.001041535710648576,
      "activeClients": {
        "total": 2,
        "writers": 0,
        "readers": 2
      }
    },
    "backgroundFlushing": {
      "last_finished": {
        "$date": 1354911272239
      },
      "last_ms": 0,
      "flushes": 59891,
      "average_ms": 4.833196974503681,
      "total_ms": 289465
    },
    "opcounters": {
      "getmore": 9622259,
      "insert": 51991653,
      "update": 7388978,
      "command": 42125248,
      "query": 4085462,
      "delete": 40
    },
    "uptime": 3593490.0,
    "ok": 1.0,
    "network": { "numRequests": 111904374, "bytesOut": 23169121531.0, "bytesIn": 9693426113.0 },
    "zone": "US-West",
    "instance": "rocketdemo",
    "version": "2.0.6",
    "asserts": { "msg": 0, "rollovers": 0, "regular": 0, "warning": 12, "user": 297 }
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Collection Details

Gets details for a collection. The following are the details for calling the Server Status Plus API :

objectrocket.stats(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.stats(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data":{
    "shardkey":{
      "unique":false,
      "lastmod":{
        "$date":1361375853
      },
      "key":"username"
    },
    "sharded":true,
    "chunks":[
      {
        "_id":"kg.test1-username_MinKey",
        "min":{
          "$minKey":1
        },
        "max":{
          "$maxKey":1
        },
        "shard":"30013",
        "ns":"kg.test1",
        "lastmod":{
          "i":0,
          "t":1
        }
      }
    ],
    "numExtents":1,
    "storageSize":8192,
    "indexSizes":{
      "_id_":8176,
      "username_1":8176
    },
    "size":0,
    "count":0,
    "totalIndexSize":16352,
    "ok":1.0,
    "avgObjSize":0.0,
    "nchunks":1,
    "shards":{
      "30013":{
        "count":0,
        "storageSize":8192,
        "ok":1.0,
        "lastExtentSize":8192,
        "totalIndexSize":16352,
        "flags":1,
        "numExtents":1,
        "nindexes":2,
        "ns":"kg.test1",
        "indexSizes":{
          "_id_":8176,
          "username_1":8176
        },
        "paddingFactor":1.0,
        "size":0
      }
    },
    "flags":1,
    "nindexes":2,
    "ns":"kg.test1"
  },
  "rc":0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Get Logs

Gets logs for the instance. The following are the details for calling the Get Logs API :

objectrocket.logs(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.logs(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "server0": [
      {
        "syslog_tag": "mongod.30047[4052]:",
        "time_rcvd": {
          "$date": 1373653720338
        },
        "syslog_fac": 1,
        "procid": "mongod.30047",
        "level": "INFO",
        "pid": "4052",
        "sys": "server0",
        "syslog_sever": 6,
        "time": {
          "$date": 1373653754000
        },
        "msg": "Fri Jul 12 11:29:14 Log entry here",
        "_id": {
          "$oid": "51e04afaf27a12257526bd4a"
        }
      }
    ],
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Get Profiling Levels

Gets profiler data for all dbs in the instance. The following are the details for calling the Get Profiling Levels API :

objectrocket.profiling_get(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.profiling_get(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "44c9fd0f3fb1450795824740a94d29f4": {
      "mydb": 1,
      "yourdb": 1,
      "slowms": 90
    }
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Set Profiling Levels

Sets the profiling levels for one or more dbs in an instance. The following are the details for calling the Get Profiling Levels API :

objectrocket.profiling_set(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • document : POST valid document with query parameter document. Example : {"level":2}.

callback : The callback function to be called after the operation is completed.

Example

Set profiling level 2 for all databases in the instance

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"level":2}
}
objectrocket.profiling_set(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "44c9fd0f3fb1450795824740a94d29f4": {
      "mydb": 2,
      "yourdb": 2
    }
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Example

Set profiling level 0 for database 'mydb'

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"db":"mydb", "level":0}
}
objectrocket.profiling_set(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": {
    "44c9fd0f3fb1450795824740a94d29f4": {
      "mydb": 0
    }
  },
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Get ACL

Get current ACLs for an instance. The following are the details for calling the Get ACL API :

objectrocket.acl_get(options, callback)

options :

  • api_key : Your ObjectRocket API key.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e"
}
objectrocket.acl_get(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": [
    {
      "cidr_mask": "1.2.3.4/32",
      "description": "Development Server in VA"
    },
    {
      "cidr_mask": "5.6.7.8/24",
      "description": "QA Lab in San Jose"
    }
  ],
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Add ACL

Add a new ACL for an instance. The following are the details for calling the Add ACL API :

objectrocket.acl_add(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • document : POST valid document with query parameter document. Example : {"cidr_mask": "1.2.3.4/32", "description": "Development Server in VA"}.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"cidr_mask": "1.2.3.4/32", "description": "Development Server in VA"}
}
objectrocket.acl_add(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": "ACL added successfully",
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}

Delete ACL

Delete an ACL for an instance. The following are the details for calling the Delete ACL API :

objectrocket.acl_delete(options, callback)

options :

  • api_key : Your ObjectRocket API key.
  • document : POST valid document with query parameter document. Example : {"cidr_mask": "1.2.3.4/32"}.

callback : The callback function to be called after the operation is completed.

Example

var options = {
  "api_key" : "2a76ebd3c2924b04afab332416e0697e",
  "document" : {"cidr_mask": "1.2.3.4/32"}
}
objectrocket.acl_delete(JSON.stringify(options), function(error, result) {
  // Your code goes here based on error or success.
});

Response

The below JSON format response is returned.

In case of success :

{
  "data": "ACL removed successfully",
  "rc": 0
}

In case of error :

{
  rc: 1,
  msg: error_message
}
1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.1.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago