Giter VIP home page Giter VIP logo

mlab-cli's Introduction

mLab CLI

npm version Dependency Status

A command-line power tool for mLab (PKA MongoLab).

mlab-cli aims to speed up some basic database management operations for your mLab account.

Dependencies

Make sure you have NPM and NodeJS installed:

$ npm --version && node --version

Installation

$ npm install --global mlab-cli

Configuration

From the official mLab Data API documentation:

API Authentication

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:

  1. Log in to the mLab management portal
  2. 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
  1. If the status is showing as “Data API Access: Disabled” in the “API Key” section, click the “Enable Data API access” button
  2. Once Data API access is enabled, your current API key will be displayed in the “API key” field
  3. (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.

Usage Example

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 databases

> show dbs
exampledb1
exampledb2
...

Set database

> use exampledb1
switched to db exampledb1

Show collections

> show collections
users
locations
...

Find documents

> find users
[{
   "_id": 56e3001a76517d7d05122b1b,
   "username": "user1",
   "active": true
}, 
{
   "_id": 56e3001a76517d7d05333b3b,
   "username": "user2",
   "active": false
}]

Return all documents with "active" field of true

> find -q '{"active": true}' users
[{
   "_id": 56e3001a76517d7d05122b1b,
   "username": "user1",
   "active": true
}]

Create new documents

> insert users testDocs.json
x document(s) added

Update one or more documents

> update -q '{"username": "user1"}' '{"active": false}' users
1 document(s) updated

Delete one or more documents

> delete -q '{"username": "user2"}' users
1 document(s) deleted

Run MongoDB database commands

> db
> ~ db: ping:1
{ serverUsed: 'ds123456-a.mlab.com:12345', ok: 1 }

Disclaimer

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.

License

MIT © Gabriel Montalvo

mlab-cli's People

Contributors

gamontal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.