Package: cbcmgr
cb-util 2.2.13Couchbase UtilitiesCouchbase connection manager. Simplifies connecting to a Couchbase cluster and performing data and management operations.Installing$ pip install cbcmgrAPI UsageOriginal syntax (package is backwards compatible):>>> from cbcmgr.cb_connect import CBConnect
>>> from cbcmgr.cb_management import CBManager
>>> bucket = scope = collection = "test"
>>> dbm = CBManager("127.0.0.1", "Administrator", "password", ssl=False).connect()
>>> dbm.create_bucket(bucket)
>>> dbm.create_scope(scope)
>>> dbm.create_collection(collection)
>>> dbc = CBConnect("127.0.0.1", "Administrator", "password", ssl=False).connect(bucket, scope, collection)
>>> result = dbc.cb_upsert("test::1", {"data": 1})
>>> result = dbc.cb_get("test::1")
>>> print(result)
{'data': 1}New Operator syntax:keyspace = "test.test.test"
db = CBOperation(hostname, "Administrator", "password", ssl=False, quota=128, create=True).connect(keyspace)
db.put_doc(col_a.collection, "test::1", document)
d = db.get_doc(col_a.collection, "test::1")
assert d == document
db.index_by_query("select data from test.test.test")
r = db.run_query(col_a.cluster, "select data from test.test.test")
assert r[0]['data'] == 'data'Thread Pool Syntax:pool = CBPool(hostname, "Administrator", "password", ssl=False, quota=128, create=True)
pool.connect(keyspace)
pool.dispatch(keyspace, Operation.WRITE, f"test::1", document)
pool.join()Async Pool Syntaxpool = CBPoolAsync(hostname, "Administrator", "password", ssl=False, quota=128, create=True)
await pool.connect(keyspace)
await pool.join()CLI UtilitiescbcutilLoad 1,000 records of data using the default schema:$ cbcutil load --host couchbase.example.com --count 1000 --schema defaultLoad data from a test file:$ cat data/data_file.txt | cbcutil load --host couchbase.example.com -b bucketExport data from a bucket to CSV (default output file location is $HOME)$ cbcutil export csv --host couchbase.example.com -i -b sample_appExport data as JSON and load that data into another cluster$ cbcutil export json --host source -i -O -q -b bucket | cbcutil load --host destination -b bucketGet a document from a bucket using the key:$ cbcutil get --host couchbase.example.com -b employees -k employees:1List information about a Couchbase cluster:$ cbcutil list --host couchbase.example.com -u developer -p passwordList detailed information about a Couchbase cluster including health information:$ cbcutil list --host couchbase.example.com --ping -u developer -p passwordReplicate buckets, indexes and users from self-managed cluster to Capella (and filter buckets beginning with "test" and users with usernames beginning with "dev"):cbcutil replicate source --host 1.2.3.4 --filter 'bucket:test.*' --filter 'user:dev.*' | cbcutil replicate target --host cb.abcdefg.cloud.couchbase.com -p "Password123#" --project dev-project --db testdbList available schemas:$ cbcutil schemaRandomizer tokensNote: Except for the US States the random data generated may not be valid. For example the first four digits of the random credit card may not represent a valid financial institution. The intent is to simulate real data. Any similarities to real data is purely coincidental.TokenDescriptiondate_timeData/time string in form %Y-%m-%d %H:%M:%Srand_credit_cardRandom credit card format numberrand_ssnRandom US Social Security format numberrand_fourRandom four digitsrand_accountRandom 10 digit numberrand_idRandom 16 digit numberrand_zip_codeRandom US Zip Code format numberrand_dollarRandom dollar amountrand_hashRandom 16 character alphanumeric stringrand_addressRandom street addressrand_cityRandom city namerand_stateRandom US State namerand_firstRandom first namerand_lastRandom last namerand_nicknameRandom string with a concatenated first initial and last namerand_emailRandom email addressrand_usernameRandom username created from a name and numbersrand_phoneRandom US style phone numberrand_boolRandom boolean valuerand_yearRandom year from 1920 to presentrand_monthRandom month numberrand_dayRandom day numberrand_date_1Near term random date with slash notationrand_date_2Near term random date with dash notationrand_date_3Near term random date with spacesrand_dob_1Date of Birth with slash notationrand_dob_2Date of Birth with dash notationrand_dob_3Date of Birth with spacesrand_imageRandom 128x128 pixel JPEG imageOptionsUsage: cbcutil command optionsCommandDescriptionloadLoad datagetGet datalistList cluster informationexportExport dataimportImport via plugincleanRemove bucketsschemaSchema management optionsreplicateReplicate configurationOptionDescription-u USER, --user USERUser Name-p PASSWORD, --password PASSWORDUser Password-h HOST, --host HOSTCluster Node or Domain Name-b BUCKET, --bucket BUCKETBucket name-s SCOPE, --scope SCOPEScope name-c COLLECTION, --collection COLLECTIONCollection name-k KEY, --key KEYKey name or pattern-d DATA, --data DATAData to import-F FILTER, --filter FILTERFilter expression (i.e. bucket:regex, user:regex, etc.)--project PROJECTCapella project name--db DATABASECapella database name-q, --quietQuiet mode (only necessary output)-O, --stdoutOutput exported data to the terminal-i, --indexCreate a primary index for export operations (if not present)--tlsEnable SSL (default)-e, --externalUse external network for clusters with an external network--schema SCHEMASchema name--count COUNTRecord Count--file FILEFile mode schema JSON file--id IDID field (for file mode)--directory DIRECTORYDirectory for export operations--deferCreates an index as deferred-P PLUGINImport plugin-V PLUGIN_VARIABLEPass variable in form key=value to pluginsgwutilDatabase Commands:CommandDescriptioncreateCreate SGW database (connect to CBS Bucket)deleteDelete a databasesyncManage Sync Function for databaseresyncReprocess documents with sync functionlistList databasedumpDump synced document detailsUser Commands:CommandDescriptioncreateCreate usersdeleteDelete userlistList usersmapCreate users based on document fieldDatabase parameters:ParameterDescription-b, --bucketBucket-n, --nameDatabase name-f, --functionSync Function file-r, --replicasNumber of replicas-g, --getDisplay current Sync FunctionUser parameters:ParameterDescription-n, --nameDatabase name-U, --sguserSync Gateway user name-P, --sgpassSync Gateway user password-d, --dbhostCouchbase server connect name or IP (for map command)-l, --dbloginCouchbase server credentials in form user:password-f, --fieldDocument field to map-k, --keyspaceKeyspace with documents for map-a, --allList all usersExamples:Create Sync Gateway database "sgwdb" that is connected to bucket "demo":sgwutil database create -h hostname -n sgwdb -b demoGet information about database "sgwdb":sgwutil database list -h hostname -n sgwdbDisplay information about documents in the database including the latest channel assignment:sgwutil database dump -h hostname -n sgwdbCreate a Sync Gateway database user:sgwutil user create -h hostname -n sgwdb --sguser sgwuser --sgpass "password"Display user details:sgwutil user list -h hostname -n sgwdb --sguser sgwuserList all database users:sgwutil user list -h hostname -n sgwdb -aCreate users in database "sgwdb" based on the unique values for document value "field_name" in keyspace "demo":sgwutil user map -h sgwhost -d cbshost -f field_name -k demo -n sgwdbAdd Sync Function:sgwutil database sync -h hostname -n sgwdb -f /home/user/demo.jsDisplay Sync Function:sgwutil database sync -h hostname -n sgwdb -gDelete user:sgwutil user delete -h hostname -n sgwdb --sguser sgwuserDelete database "sgwdb":sgwutil database delete -h hostname -n sgwdbcaputilNote: Save Capella v4 token file as $HOME/.capella/default-api-key-token.txtCreate Capella cluster:caputil cluster create --project project-name --name testdb --region us-east-1Update Capella cluster (to add services):caputil cluster update --project pytest-name --name testdb --services search,analytics,eventingDelete Capella cluster:caputil cluster delete --project project-name --name testdb --region us-east-1Create bucket:caputil bucket create --project project-name --db testdb --name test-bucketChange database user password:caputil user password --project pytest-name --db testdb --name Administrator