Module 3 - Create a Couchbase Bucket, Export And Import a Couchbase Bucket

Module 3 -

Create a Couchbase Bucket

Export And Import a Couchbase Bucket

Load data using cbdocloader

Create a bucket:

CLI:

/opt/couchbase/bin/couchbase-cli bucket-create -c 127.0.0.1:8091 --username Administrator \
--password couchbase --bucket CLI --bucket-type couchbase \
--bucket-ramsize 100 --bucket-replica 0 --bucket-priority high \
--bucket-eviction-policy fullEviction --enable-flush 1 \
--enable-index-replica 1

REST:

curl -X POST -u Administrator:couchbase http://127.0.0.1:8091/pools/default/buckets \
-d name=REST -d ramQuotaMB=100 -d replicaNumber=1 \
-d bucketType=couchbase -d maxTTL=60 \
-d compressionMode=passive
 

Edit a Bucket Using REST API

curl -X POST -u Administrator:couchbase http://127.0.0.1:8091/pools/default/buckets/REST \
-d bucketType=couchbase \
-d autoCompactionDefined=false \
-d evictionPolicy=fullEviction \
-d threadsNumber=2 \
-d replicaNumber=0 \
-d compressionMode=passive \
-d maxTTL=20000 \
-d replicaIndex=0 \
-d ramQuotaMB=100 \
-d flushEnabled=0
 

Loading dummy data

/opt/couchbase/bin/cbworkloadgen -n 127.0.0.1:8091 -b REST -u Administrator -p couchbase \
-i 1000000 -j -r 1 -s 10240
 

Export and Import a Couchbase bucket:

Export:

To export data to /data/lines.json using the lines format(with 4 threads):

/opt/couchbase/bin/cbexport json -c couchbase://127.0.0.1 -u Administrator -p couchbase -b REST -o /data/lines.json -f lines -t 4

Export data using the list format:

/opt/couchbase/bin/cbexport json -c couchbase://127.0.0.1 -u Administrator -p couchbase -b REST -o /data/list.json -f list -t 4

Import:

cbimport csv - Imports CSV data into Couchbase
Import data from /data/people.csv using a key containing the fname column(4 threads)

/opt/couchbase/bin/cbimport csv -c couchbase://127.0.0.1 -u Administrator -p couchbase -b REST-TMP -d file:///data/people.csv -g key::%fname% -t 4
    
/opt/couchbase/bin/cbimport csv -c couchbase://127.0.0.1 -u Administrator -p couchbase -b REST-TMP -d file:///data/people.csv -g %pincode% -t 4

cbimport json - Imports JSON data into Couchbase
Import data from /data/lines.json using a key containing the "type" field(4 threads)


/opt/couchbase/bin/cbimport json -c couchbase://127.0.0.1 -u Administrator -p couchbase -b REST-TMP -d file:///data/lines.json -f lines -g key::%type% -t 4
    
Import data from /data/list.json using a key containing the "name" field and then a unique id separated by a # we could use the --generator-delimiter flag to avoid escaping the # sign.

/opt/couchbase/bin/cbimport json -c couchbase://127.0.0.1 -u Administrator -p couchbase -b REST-TMP -d file:///data/list.json -f list --generator-delimiter '\t' \
-g key::%name%#UUID# -t 4

cbdocloader

The cbdocloader tool is used to load a group of JSON documents in a given directory or in a single .zip file into a Couchbase bucket.

    /opt/couchbase/bin/cbdocloader -c couchbase://127.0.0.1 -u Administrator -p couchbase -m 100 -b REST-TMP -d /data/docs/ -t 4 --verbose

    /opt/couchbase/bin/cbdocloader -c couchbase://127.0.0.1 -u Administrator -p couchbase -m 100 -b REST -d /data/docs.zip -t 4 --verbose

Sample documents:

{
"click":"to edit",
"with JSON":"there are no reserved field names"
}

{
"type":"home needs",
"name":"chair",
"zipcode":"500081",
"owner":"Baby"
}

{
"name":"Joshith",
"zipcode":"522265"
}

{
"name":"Sravan",
"zipcode":"500081"
}

{
"type":"electronics",
"name":"mobile",
"zipcode":"522265",
"owner":"Kishore Uppala"
}

sample csv:

fname,lname,pincode
Kishore,Uppala,522263
Baby,Uppala,522264
Joshith,Uppala,522265


Note: Above are the commands used in Module 3 of the Couchbase Database Administration Course.

 

DISCLAIMER

Use the content of this website at your own risk.

The purpose of sharing the content on this website is to Educate. The author/owner of the content do not warrant that the information provided on this website is fully complete and shall not be responsible for any errors or omissions.The author/owner shall have neither liability nor responsibility to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the contents of this website.

This content has been shared under Educational And Non-Profit Purposes Only. The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

For Copyright Content Removal Please Contact us by Email at besttechreads[at]gmail.com

Post a Comment

Previous Post Next Post