This nbcli is a simple command line interface for NoSQLBooster. It allows you to run javascript or SQL query statement, javascript file and NoSQLBooster tasks in terminal or integrate NoSQLBooster into your continuous development. This nbcli supports all NoSQLBooster shell extensions, SQL Query, fluent Query API, 3rd party library (lodash, momentjs ...) and Node.js modules installed under user data directory (Menu-> Help-> Open User Data directory)
To be clear, nbcli is not a REPL (Read Evaluate Print Loop) tool.
Get Started
To start nbcli, click "Menu -> Tools -> Open NoSQLBooster Command Line ...", you can use "Menu -> Options -> Add Command Line to path..." to add nbcli to user's PATH. Once add nbcli to users' path, you can access to nbcli in the traditional Command Prompt.
Usages
The usage options are simple:
Usages:
>> nbcli -h
nbcli [db_address] [script] [options]
Positionals:
db_address MongoDB URI or NoSQLBooster connection name/id
can be:
my_connection my_connection is NoSQLBooster connection name
my_connection/foo foo database on my_connection
192.168.0.1/foo foo database on 192.168.0.1 machine
192.168.0.1:9999/foo foo database on 192.168.0.1 machine on port 9999
mongodb://192.168.0.1:9999/foo URI, foo database on 192.168.0.1 port 9999 [string]
script script to run
can be:
db.users.find() javascript statement
select * from users sql select statement
./test.js javascript file to run (ending in .js) [string]
Options:
--version Show version number [boolean]
--task to run import/export/restore/backup/query task
can be task id or task name [string]
--verbose verbose mode [boolean]
--nodb do not connect to mongodb - no 'db_address' arg expected [boolean]
-u, --username username for authentication [string]
-p, --password password for authentication [string]
-h, --help Show help [boolean]
Examples:
nbcli localhost:27017 "select name, address.email as email from users" run SQL query
nbcli test_connection "db.users.select('address.city, name').limit(10)" run javascript statement
nbcli "mongodb://localhost/test" ~/test.js run test.js javascript file
nbcli --task 'my_mongo_backup_task' run mongobackup task
copyright 2020 https://www.nosqlbooster.com
Here is an example to list all the collections in the current db:
nbcli "localhost/mb-user-mgr" "select * from mborders"
How to Run Javascript Statements?
The following example lists all the datasets of the test database.
nbcli localhost/test "show dbs"
The first command line argument is the [db_address] of the database, the [db_address] can be HOST:PORT/database, MongoDB URI or NoSQLBooster connection name/id. The second argument is the javascript statement which supports all NoSQLBooster shell extensions, SQL Query, fluent Query API, 3rd party library (lodash, momentjs ...) and Node.js modules installed under user data directory.
The results are as follows
NoSQLBooster command line version v8.0.0
Connecting to: mongodb://localhost:27017/test at 1/10/2022, 4:30:30 PM
MongoDB Server Version 4.2.7
NoSQLBoosterSamples 0.000GB
admin 0.000GB
config 0.000GB
demo 1.300GB
local 0.013GB
runSQLQueryDemo 0.000GB
sample 2.201GB
test 0.003GB
The following example runs a NoSQLBooster fluent Query.
nbcli localhost/test "db.user.where('age').gte(18).lte(65).select('name age -_id').sort('-age name')"
The following example runs an aggregation.
nbcli localhost/test "db.unicorns.aggregate().group({_id: '$gender', count: {$sum: 1}}).sort('-count')"
How to Run Javascript File?
Just change the javascript statement of the second argument to the path of the js file The following example run a simple javascript file which contains only one line "db.getName()".
echo db.getName() > ~/tmp/get_db_name.js
nbcli localhost/test ~/tmp/get_db_name.js
The results are as follows
NoSQLBooster command line version v8.0.0
Connecting to: mongodb://localhost:27017/test at 6/1/2020, 4:30:30 PM
MongoDB Server Version 4.2.7
"test"
How to Run SQL Query?
The way to run the SQL query is quite straightforward. Just change the javascript statement of the second argument to the SQL query statement that begins with SELECT. The following example run SQL GROUP BY Statement.
nbcli localhost/test "SELECT gender, COUNT(*) AS count FROM unicorns GROUP BY gender"
The results are as follows
NoSQLBooster command line version v8.0.0
Connecting to: mongodb://localhost:27017/test at 1/10/2022, 4:30:30 PM
MongoDB Server Version 4.4.7
[
{
"_id" : {
"gender" : "f"
},
"gender" : "f",
"count" : 5
},
{
"_id" : {
"gender" : "m"
},
"gender" : "m",
"count" : 7
}
]
How to Run a Task?
The option "--task" allow you to run import/export/restore/backup/query NoSQLBooster task.
The following example run a mongodump task. The "my_mongo_backup_task" is the name of the task. There is no need to provide a database address to run the task because the task always specifies the default target database. If the connection address is specified on the command line, the specified address will overwrite the default target database in the task.
nbcli --task my_mongo_backup_task
