©2015 - 2022 Chad’s Technoworks. Disclaimer and Terms of Use

Chad’s TechnoWorks My Journal On Technology

Information Technology

COUCHBASE CLI TOOLS

Couchbase command line interface is a set of tools that provides monitoring utilities, querying tools, data loading tools and cluster management.


TABLE OF CONTENTS


N1QL Query Tool - cbq

Data Loader Tool - cbdocloader

Query Workbench

  Install Query Workbench

  Configure Query Workbench

  Launching Query Workbench Web Services  






DATA LOADER TOOL - CBDOCLOADER


JSON document loader tool. Reads *.json files stored on a directory or zip file.


Directory structure

Place the files into the following directories according to their type as designated below:

/design_docs    # directory to place all the design docs for views.

/docs           # directory to place all the json data files. This can contain other sub directories too.


Note that each json file is treated as a single json doc for which the filename will be used as a Key ID.


Available parameter options:


[couchbas@lxnode5 ~]$ cbdocloader -h

Usage: cbdocloader [options] <directory>|zipfile


Example: cbdocloader -u Administrator -p password -n 127.0.0.1:8091 -b mybucket -s 100 gamesim-sample.zip


Options:

  -h, --help         show this help message and exit

  -u Administrator   Username

  -p password        Password

  -b mybucket        Bucket

  -n 127.0.0.1:8091  Node address

  -s 100             RAM quota in MB

[couchbas@lxnode5 ~]$


Note:

-s   default 100mb

-u   alternatively can use CB_REST_USERNAME environment variable

-p   alternatively can use CB_REST_PASSWORD environment variable

-b   if omitted, will use default bucket. If the bucket is not found it will be created first.



[couchbas@lxnode5 sample]$ cbdocloader -n lxnode5:8091 -u Administrator -p mypass -b loadbucket gamesim-sample.zip

[2016-03-16 11:43:59,214] - [rest_client] [139758842296064] - INFO - existing buckets : [u'CRUD_Lab', u'default', u'syncGW_CRUD_Lab', u'sync_gateway', u'travel-sample-dc2']

[2016-03-16 11:43:59,269] - [rest_client] [139758842296064] - INFO - http://lxnode5:8091//pools/default/buckets with param: proxyPort=11211&bucketType=membase&authType=sasl&name=loadbucket&replicaNumber=1&saslPassword=&ramQuotaMB=100

[2016-03-16 11:44:00,649] - [rest_client] [139758842296064] - INFO - existing buckets : [u'CRUD_Lab', u'default', u'loadbucket', u'syncGW_CRUD_Lab', u'sync_gateway', u'travel-sample-dc2']

[2016-03-16 11:44:00,650] - [rest_client] [139758842296064] - INFO - found bucket loadbucket

bucket creation is successful

[couchbas@lxnode5 sample]$


[couchbas@lxnode5 sample]$ cbdocloader -n lxnode5:8091 -u Administrator -p mypass -b loadbucket gamesim-sample.zip

[2016-03-16 13:45:32,051] - [rest_client] [140374895077120] - INFO - existing buckets : [u'CRUD_Lab', u'default', u'loadbucket', u'syncGW_CRUD_Lab', u'sync_gateway', u'travel-sample-dc2']

[2016-03-16 13:45:32,052] - [rest_client] [140374895077120] - INFO - found bucket loadbucket

bucket creation is successful

.

bucket: gamesim-sample.zip, msgs transferred...

       :                total |       last |    per sec

 byte  :                94693 |      94693 |    97976.1

done

[couchbas@lxnode5 sample]$


NOTE: The filename for each json doc becomes the Key ID in the bucket.


[couchbas@lxnode5 sample]$ ls gamesim-sample/docs | more

Aaron0.json

Aaron1.json

Aaron2.json

Aliaksey0.json

Aliaksey1.json

Aliaksey2.json

...

... cut ...

...

[couchbas@lxnode5 sample]$


[couchbas@lxnode5 sample]$ cat gamesim-sample/docs/Aaron2.json

{

    "experience": 55,

    "hitpoints": 10,

    "jsonType": "player",

    "level": 2,

    "loggedIn": true,

    "name": "Aaron2",

    "uuid": "edc5aedf-9cb6-4c11-90d4-9645083053e8"

}

[couchbas@lxnode5 sample]$


[couchbas@lxnode4 ~]$ cbc cat Aaron2 -U http://lxnode5.vlabs.net/loadbucket

Aaron2               CAS=0x26cf46673c14, Flags=0x0. Size=190

{

    "experience": 55,

    "hitpoints": 10,

    "jsonType": "player",

    "level": 2,

    "loggedIn": true,

    "name": "Aaron2",

    "uuid": "edc5aedf-9cb6-4c11-90d4-9645083053e8"

}


[couchbas@lxnode4 ~]$



QUERY WORKBENCH

The Query Workbench is a browser based graphical tool used for N1QL queries and execution.

It usually is installed as a client in your development workstations and it supports the most common OS platforms such as Mac OS X, Windows and Linux.

Since this is a N1QL tool, buckets must have at least a primary index in order for the queries to work.


You may download the appropriate installer for your platform from Couchbase Download Site , select the "Tools" tab and look for the current release.

Keep in mind, since this is a browser based tool, it has a mini-webserver when you run the program.


NOTE: At the time of this writing, the Couchbase Query Workbench is in Developer Preview release and is a separate tool. There were plans for it to be incorporated into the Couchbase Server Console on its v4.5+ release.


Features of the Query Workbench include:




Install Query Workbench


An example of a Linux installation:


[couchbas@lxnode4 couchbase]$ gunzip couchbase-query-workbench_dp2-linux_x86_64.tar.gz


[couchbas@lxnode4 couchbase]$ tar xvf couchbase-query-workbench_dp2-linux_x86_64.tar


 


Configure Query Workbench

NOTE: If Query Workbench is installed remotely from the Couchbase cluster, the configuration for node connection has to be on a host that runs the Query Service and appropriate firewall ports need to opened between the client and the CB cluster.



[couchbas@lxnode4 couchbase]$ cd couchbase-query-workbench

[couchbas@lxnode4 couchbase-query-workbench]$ ls

cbq-gui  launch-cbq-gui.sh  LICENSE.txt  static

[couchbas@lxnode4 couchbase-query-workbench]$ ls -l

total 15840

-rwxr-xr-x. 1 couchbas nosql 16205336 Jan 25 19:35 cbq-gui

-rwxr-xr-x. 1 couchbas nosql     1341 Jan 25 19:35 launch-cbq-gui.sh

-rwxr-xr-x. 1 couchbas nosql     2462 Jan 25 19:35 LICENSE.txt

drwxr-xr-x. 8 couchbas nosql     4096 Jan 25 19:35 static

[couchbas@lxnode4 couchbase-query-workbench]$


[couchbas@lxnode4 couchbase-query-workbench]$ vi launch-cbq-gui.sh


Replace COUCHBASE_URL=http://127.0.0.1:8091 with your cluster node host and port.

In my case, it would be COUCHBASE_URL=http://lxnode5.vlabs.net:8091



Launching CBQWB Web Services


This is an example of running the Query workbench web services in Linux:


[couchbas@lxnode4 couchbase-query-workbench]$ ./launch-cbq-gui.sh

Running: ./cbq-gui -datastore=http://lxnode5.vlabs.net:8091 -localPort=:8094 -user= -pass=

Launching query web service.

    Using CB Server at: http://lxnode5.vlabs.net:8091

    Using N1QL query service on: lxnode5.vlabs.net:8093

    Using memcached service on: lxnode5.vlabs.net:11210

    Using memcached service on: 172.16.33.89:11210

    Using web content at: ./static

Launching UI server, to use, point browser at http://localhost:8094