
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mlab-data-api
Advanced tools
mlab-data-api is a node.js module designed to allow you to access mLab's Data API with minimal overhead from browser-side.
Inspired by mongolab Data API
Using npm:
$ npm install --save mlab-data-api
If you don't have or don't want to use npm:
$ cd ~/.node_modules
$ git clone git://github.com/bgrusnak/mlab-data-api.git
To require the library and initialize it
import MLab from 'mlab-data-api';
var mLab=MLab({
key: '<YOUR MLAB API DATA KEY>',
host:'https://api.mlab.com', //optional
uri : '/api',//optional
version :'1',//optional
database:'your working database', //optional
timeout : 10000 //optional
})
List databases
mLab.listDatabases()
.then(function (response) {
console.log('got',response.data)
})
.catch(function (error) {
console.log('error', error)
})
List collections
mLab.listCollections('exampledb')
.then(function (response) {
console.log('got',response.data)
})
.catch(function (error) {
console.log('error', error)
})
List documents
var options = {
database: 'exampledb', //optional
collection: 'examples',
query: { 'key': 'value' }
};
mLab.listDocuments(options)
.then(function (response) {
console.log('got',response.data)
})
.catch(function (error) {
console.log('error', error)
});
All methods returns the Promises for further processing
listDatabasesGet the databases linked to the authenticated account
.listDatabases()
listCollectionsGet the collections in the specified database
.listCollections(database)
Parameters:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
listDocumentsGet the documents in the specified collection
.listDocuments(options)
Options:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
| collection | MongoDB collection name | String | Yes |
| query | restrict results by the specified JSON query | Object | No |
| count | return the result count for this query | Boolean | No |
| fields | specify the set of fields to include or exclude in each document (1 - include; 0 - exclude) | Object | No |
| findOne | return a single document from the result set (same as findOne() using the mongo shell) | Boolean | No |
| order | specify the order in which to sort each specified field (1- ascending; -1 - descending) | String | No |
| skip | number of documents to skip | Number | No |
| limit | number of documents to return | Number | No |
insertDocumentsCreate a new document in the specified collection
.insertDocuments(options)
Options:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
| collection | MongoDB collection name | String | Yes |
| data | a document or array of documents to be inserted | Object/Array | Yes |
updateDocumentsUpdate one or more documents in the specified collection
.updateDocuments(options)
Options:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
| collection | MongoDB collection name | String | Yes |
| data | replacement document or update modifiers | Object | Yes |
| query | only update document(s) matching the specified JSON query | Object | No |
| all | update all documents collection or query (if specified). By default only one document is modified | Boolean | No |
| upsert | insert the document defined in the request body if none match the specified query | Boolean | No |
deleteDocumentsReplace the contents of some or all documents of a collection
.deleteDocuments(options)
Options:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
| collection | MongoDB collection name | String | Yes |
| query | only replace the document(s) matching the specified JSON query | Object | No |
viewDocumentView a single document
.viewDocument(options)
Options:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
| collection | MongoDB collection name | String | Yes |
| id | the document's id | String | Yes |
updateDocumentUpdate a single document
.updateDocument(options)
Options:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
| collection | MongoDB collection name | String | Yes |
| id | the document's id | String | Yes |
| updateObject | object sent as replacement | Object | Yes |
deleteDocumentDelete a single document
.deleteDocument(options)
Options:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
| collection | MongoDB collection name | String | Yes |
| id | the document's id | String | Yes |
runCommandRun a MongoDB database command
.runCommand(options)
Options:
| Name | Description | Type | Required |
|---|---|---|---|
| database | MongoDB database name | String | No |
| commands | MongoDB database command | Object | Yes |
mLab databases can be accessed by your application code in two ways.
The first method - the one we strongly recommend - is to connect using one of the MongoDB drivers (as described above). You do not need to use our API if you use the driver. In fact, using a driver provides better performance, better security, and more functionality.
The second method is to connect via mLab’s RESTful Data API. Use this method only if you cannot connect using a MongoDB driver.
Visit mLab's official documentation if you have any security concerns about using the Data API
If you run into problems, have questions, or whatever else you can open an issue on this repository. If you'd like to submit a patch, shoot me a pull request. I'd like to keep this module simple, so if you want to add all kinds of crazy functionality - you might want to fork. When in doubt, send a pull request - the worst that can happen is that I won't merge it.
mongolab-data-api: A node.js module for mLab (PKA MongoLab)
MIT © Ilya Shlyakhovoy
FAQs
mLab data api for client-side projects
We found that mlab-data-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.