mlab-cli
aims to speed up some basic database management operations for your mLab account.
Make sure you have NPM and NodeJS installed:
$ npm --version && node --version
$ npm install --global mlab-cli
From the official mLab Data API documentation:
Each API request must pass an apiKey query parameter. By default, access to the Data API is disabled and must be enabled before you can obtain your API key.
Follow these steps to enable Data API access and obtain your API key:
- Log in to the mLab management portal
- Click your username (not the account name) in the upper right-hand corner to open your account user profile
- If you are already in the account details page, then click on the row with your username in the Account Users section
- If the status is showing as “Data API Access: Disabled” in the “API Key” section, click the “Enable Data API access” button
- Once Data API access is enabled, your current API key will be displayed in the “API key” field
- (Optional) If you want to update the current key, click “Regenerate API key”
Once you've enabled an API key for your account use the authorize
command to set up your key, otherwise you'll receive an error that looks like this:
Error: account unauthorized, please provide a valid API key.
Your account key is stored in a YAML-formatted file located at /usr/local/lib/node_modules/mlab-cli/.mlabrc.yml
.
NOTE: Your API key will give full access to all data within the databases belonging to your mLab account. If you distribute it to untrusted individuals, they can gain access to your account and your data.
Typing help
will list all the available commands. You can type help TASK
to get help for a specific command.
$ mlab
mLab CLI version: x.x.x
> help
> show dbs
exampledb1
exampledb2
...
> use exampledb1
switched to db exampledb1
> show collections
users
locations
...
> find users
[{
"_id": 56e3001a76517d7d05122b1b,
"username": "user1",
"active": true
},
{
"_id": 56e3001a76517d7d05333b3b,
"username": "user2",
"active": false
}]
> find -q '{"active": true}' users
[{
"_id": 56e3001a76517d7d05122b1b,
"username": "user1",
"active": true
}]
> insert users testDocs.json
x document(s) added
> update -q '{"username": "user1"}' '{"active": false}' users
1 document(s) updated
> delete -q '{"username": "user2"}' users
1 document(s) deleted
> db
> ~ db: ping:1
{ serverUsed: 'ds123456-a.mlab.com:12345', ok: 1 }
I wrote this utility for my own convenience. I think that others might find it useful as well. Also, I am not responsible for any misuse or damage that may arise from the use of your database information presented through this tool.
- mongolab-data-api: A NodeJS wrapper for mLab’s Data API
MIT © Gabriel Montalvo