.\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . .TH "CBC\-SUBDOC" "1" "April 2019" "" "" . .SH "NAME" \fBcbc\-subdoc\fR \- Interactively Inspect Document Using Subdocument API . .SH "SYNOPSIS" \fBcbc\-subdoc\fR [\fIOPTIONS\fR] . .SH "DESCRIPTION" \fBcbc\-subdoc\fR runs an interactive shell with commands from subdocument API\. . .P \fI\fR . .SH "OPTIONS" Options may be read either from the command line, or from a configuration file (see cbcrc(4)): . .P The following options control workload generation: . .TP \fB\-U\fR, \fB\-\-spec\fR=\fISPEC\fR A string describing the cluster to connect to\. The string is in a URI\-like syntax, and may also contain other options\. See the \fIEXAMPLES\fR section for information\. Typically such a URI will look like \fBcouchbase://host1,host2,host3/bucket\fR\. . .IP The default for this option is \fBcouchbase://localhost/default\fR . .TP \fB\-u\fR, \fB\-\-username\fR=\fIUSERNAME\fR Specify the \fIusername\fR for the bucket\. Since Couchbase 5\.x this is mandatory switch, and it must specify the name of the user exisiting on cluster (read more at "Security/Authorization" section of the server manual)\. For older servers this field should be either left empty or set to the name of the bucket itself\. . .TP \fB\-P\fR, \fB\-\-password\fR=\fIPASSWORD\fR: . .TP \fB\-P \-\fR, \fB\-\-password=\-\fR Specify the password for the bucket\. As for servers before 5\.x this was only needed if the bucket is protected with a password\. For cluster version after 5\.x, the password is mandatory, and should match the selected account (read more at "Security/Authorization" section of the server manual)\. . .IP Specifying the \fB\-\fR as the password indicates that the program should prompt for the password\. You may also specify the password on the commandline, directly, but is insecure as command line arguments are visible via commands such as \fBps\fR\. . .TP \fB\-T\fR, \fB\-\-timings\fR Dump command timings at the end of execution\. This will display a histogram showing the latencies for the commands executed\. . .TP \fB\-v\fR, \fB\-\-verbose\fR Specify more information to standard error about what the client is doing\. You may specify this option multiple times for increased output detail\. . .TP \fB\-D\fR, \fB\-\-cparam\fR=OPTION=VALUE Provide additional client options\. Acceptable options can also be placed in the connection string, however this option is provided as a convenience\. This option may be specified multiple times, each time specifying a key=value pair (for example, \fB\-Doperation_timeout=10 \-Dconfig_cache=/foo/bar/baz\fR)\. See \fIADDITIONAL OPTIONS\fR for more information . .TP \fB\-y\fR, \fB\-\-compress\fR Enable compressing of documents\. When the library is compiled with compression support, this option will enable Snappy compression for outgoing data\. Incoming compressed data handled automatically regardless of this option\. Note, that because the compression support have to be negotiated with the server, first packets might be sent uncompressed even when this switch was specified\. This is because the library might queue data commands before socket connection has been established, and the library will negotiate compression feature\. If it is known that all server support compression repeating the switch (like \fB\-yy\fR) will force compression for all outgoing mutations, even scheduled before establishing connection\. . .TP \fB\-\-truststorepath\fR=\fIPATH\fR The path to the server\'s SSL certificate\. This is typically required for SSL connectivity unless the certificate has already been added to the OpenSSL installation on the system (only applicable with \fBcouchbases://\fR scheme) . .TP \fB\-\-certpath\fR=\fIPATH\fR The path to the server\'s SSL certificate\. This is typically required for SSL connectivity unless the certificate has already been added to the OpenSSL installation on the system (only applicable with \fBcouchbases://\fR scheme)\. This also should contain client certificate when certificate authentication used, and in this case other public certificates could be extracted into \fBtruststorepath\fR chain\. . .TP \fB\-\-keypath\fR=\fIPATH\fR The path to the client SSL private key\. This is typically required for SSL client certificate authentication\. The certificate itself have to go first in chain specified by \fBcertpath\fR (only applicable with \fBcouchbases://\fR scheme) . .TP \fB\-\-dump\fR Dump verbose internal state after operations are done\. . .P \fI\fR . .SH "ADDITIONAL OPTIONS" The following options may be included in the connection string (via the \fB\-U\fR option) as URI\-style query params (e\.g\. \fBcouchbase://host/bucket?option1=value1&option2=value2\fR) or as individual key=value pairs passed to the \fB\-D\fR switch (e\.g\. \fB\-Doption1=value1 \-Doption2=value\fR)\. The \fB\-D\fR will internally build the connection string, and is provided as a convenience for options to be easily passed on the command\-line . .IP "\(bu" 4 \fBoperation_timeout=SECONDS\fR: Specify the operation timeout in seconds\. This is the time the client will wait for an operation to complete before timing it out\. The default is \fB2\.5\fR . .IP "\(bu" 4 \fBconfig_cache=PATH\fR: Enables the client to make use of a file based configuration cache rather than connecting for the bootstrap operation\. If the file does not exist, the client will first connect to the cluster and then cache the bootstrap information in the file\. . .IP "\(bu" 4 \fBtruststorepath=PATH\fR: The path to the server\'s SSL certificate\. This is typically required for SSL connectivity unless the certificate has already been added to the OpenSSL installation on the system (only applicable with \fBcouchbases://\fR scheme) . .IP "\(bu" 4 \fBcertpath=PATH\fR: The path to the server\'s SSL certificate\. This is typically required for SSL connectivity unless the certificate has already been added to the OpenSSL installation on the system (only applicable with \fBcouchbases://\fR scheme)\. This also should contain client certificate when certificate authentication used, and in this case other public certificates could be extracted into \fBtruststorepath\fR chain\. . .IP "\(bu" 4 \fBkeypath=PATH\fR: The path to the client SSL private key\. This is typically required for SSL client certificate authentication\. The certificate itself have to go first in chain specified by \fBcertpath\fR (only applicable with \fBcouchbases://\fR scheme) . .IP "\(bu" 4 \fBipv6=allow\fR: Enable IPv6\. . .IP "\(bu" 4 \fBssl=no_verify\fR: Temporarily disable certificate verification for SSL (only applicable with \fBcouchbases://\fR scheme)\. This should only be used for quickly debugging SSL functionality\. . .IP "\(bu" 4 \fBsasl_mech_force=MECHANISM\fR: Force a specific \fISASL\fR mechanism to be used when performing the initial connection\. This should only need to be modified for debugging purposes\. The currently supported mechanisms are \fBPLAIN\fR and \fBCRAM\-MD5\fR . .IP "\(bu" 4 \fBbootstrap_on=\fR: Specify the bootstrap protocol the client should use when attempting to connect to the cluster\. Options are: \fBcccp\fR: Bootstrap using the Memcached protocol (supported on clusters 2\.5 and greater); \fBhttp\fR: Bootstrap using the HTTP REST protocol (supported on any cluster version); and \fBboth\fR: First attempt bootstrap over the Memcached protocol, and use the HTTP protocol if Memcached bootstrap fails\. The default is \fBboth\fR . .IP "\(bu" 4 \fBenable_tracing=true/false\fR: Activate/deactivate end\-to\-end tracing\. . .IP "\(bu" 4 \fBtracing_orphaned_queue_flush_interval=SECONDS\fR: Flush interval for orphaned spans queue in default tracer\. This is the time the tracer will wait between repeated attempts to flush most recent orphaned spans\. Default value is 10 seconds\. . .IP "\(bu" 4 \fBtracing_orphaned_queue_size=NUMBER\fR: Size of orphaned spans queue in default tracer\. Queues in default tracer has fixed size, and it will remove information about older spans, when the limit will be reached before flushing time\. Default value is 128\. . .IP "\(bu" 4 \fBtracing_threshold_queue_flush_interval=SECONDS\fR: Flush interval for spans with total time over threshold in default tracer\. This is the time the tracer will wait between repeated attempts to flush threshold queue\. Default value is 10 seconds\. . .IP "\(bu" 4 \fBtracing_threshold_queue_size=NUMBER\fR: Size of threshold queue in default tracer\. Queues in default tracer has fixed size, and it will remove information about older spans, when the limit will be reached before flushing time\. Default value is 128\. . .IP "\(bu" 4 \fBtracing_threshold_kv=SECONDS\fR: Minimum time for the tracing span of KV service to be considered by threshold tracer\. Default value is 0\.5 seconds\. . .IP "\(bu" 4 \fBtracing_threshold_query=SECONDS\fR: Minimum time for the tracing span of QUERY service to be considered by threshold tracer\. Default value is 1 second\. . .IP "\(bu" 4 \fBtracing_threshold_view=SECONDS\fR: Minimum time for the tracing span of VIEW service to be considered by threshold tracer\. Default value is 1 second\. . .IP "\(bu" 4 \fBtracing_threshold_search=SECONDS\fR: Minimum time for the tracing span of SEARCH service to be considered by threshold tracer\. Default value is 1 second\. . .IP "\(bu" 4 \fBtracing_threshold_analytics=SECONDS\fR: Minimum time for the tracing span of ANALYTICS service to be considered by threshold tracer\. Default value is 1 second\. . .IP "" 0 . .P \fI\fR . .SH "COMMANDS" . .SS "help" Show list of accessible commands with short help\. . .SS "LOOKUP COMMANDS" The following options are supported for lookup commands: . .IP "\(bu" 4 \fB\-?\fR, \fB\-\-help\fR: Display built\-in help . .IP "\(bu" 4 \fB\-p\fR, \fB\-\-path\fR \fIPATH\fR: JSON path in the document\. Read more about paths in the documentation \fIhttps://developer\.couchbase\.com/documentation/server/current/n1ql/n1ql\-intro/queriesandresults\.html#story\-h2\-2\fR\. . .IP "\(bu" 4 \fB\-x\fR, \fB\-\-xattr\fR \fIPATH\fR: JSON path in the extended attributes\. . .IP "\(bu" 4 \fB\-d\fR, \fB\-\-deleted\fR Access XATTR attributes of deleted documents\. . .IP "" 0 . .SS "get" \fBget\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Retrieve path from the item on the server\. . .P This command requires that at least one key passed to it\. If no paths are specified, it will fetch full document\. . .SS "exists" \fBexists\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Check if path exists in the item on the server\. . .P This command requires that at least one key and one path are passed to it\. Command has alias \fBexist\fR\. . .SS "size" \fBsize\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Count the number of elements in an array or dictionary\. The command has alias \fBget\-count\fR\. . .P This command requires that at least one key and one path passed to it\. . .SS "MUTATION COMMANDS" The mutation commands below support the following options: . .TP \fB\-x\fR, \fB\-\-xattr\fR \fIPATH=VALUE\fR Store XATTR path (exentnded attributes)\. . .TP \fB\-p\fR, \fB\-\-path\fR \fIPATH=VALUE\fR JSON path in the document\. Read more about paths in the documentation \fIhttps://developer\.couchbase\.com/documentation/server/current/n1ql/n1ql\-intro/queriesandresults\.html#story\-h2\-2\fR\. . .TP \fB\-e\fR, \fB\-\-expiry\fR \fITIME\fR Expiration time in seconds\. Relative (up to 30 days) or absolute (as Unix timestamp)\. . .TP \fB\-i\fR, \fB\-\-intermediates\fR Create intermediate paths [Default=FALSE]\. . .TP \fB\-u\fR, \fB\-\-upsert\fR Create document if it does not exist [Default=FALSE]\. . .SS "replace" \fBreplace\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Replace the value at the specified path\. . .SS "dict\-add" \fBdict\-add\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Add the value at the given path, if the given path does not exist\. . .SS "dict\-upsert" \fBdict\-upsert\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Unconditionally set the value at the path\. . .SS "array\-add\-first" \fBarray\-add\-first\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Prepend the value(s) to the array\. All array operations may accept multiple objects\. See examples below\. . .SS "array\-add\-last" \fBarray\-add\-last\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Append the value(s) to the array\. . .SS "array\-add\-unique" \fBarray\-add\-unique\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Add the value to the array indicated by the path, if the value is not already in the array\. . .SS "array\-insert" \fBarray\-insert\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Add the value at the given array index\. Path must include index, e\.g\. \fBmy\.list[4]\fR . .SS "counter" Increment or decrement an existing numeric path\. The value must be 64\-bit integer\. . .SS "set" \fBset\fR [OPTIONS\[char46]\[char46]\[char46]] KEY VALUE . .P Store document on the server\. . .P This command requires exactly two argument, key and value\. Command has alias \fBupsert\fR\. If no XATTR specified, the command will add its version to the path \fB_cbc\.version\fR\. . .TP \fB\-x\fR, \fB\-\-xattr\fR \fIPATH=VALUE\fR Store XATTR path (exentnded attributes) . .TP \fB\-e\fR, \fB\-\-expiry\fR \fITIME\fR Expiration time in seconds\. Relative (up to 30 days) or absolute (as Unix timestamp) . .SS "remove" \fBremove\fR [OPTIONS\[char46]\[char46]\[char46]] KEY\[char46]\[char46]\[char46] . .P Remove path in the item on the server\. . .P This command requires at least one key\. If no paths specified, it will remove whole document\. . .TP \fB\-p\fR, \fB\-\-path\fR \fIPATH\fR JSON path in the document\. Read more about paths in the documentation \fIhttps://developer\.couchbase\.com/documentation/server/current/n1ql/n1ql\-intro/queriesandresults\.html#story\-h2\-2\fR\. . .TP \fB\-x\fR, \fB\-\-xattr\fR \fIPATH\fR JSON path in the extended attributes\. . .P \fI\fR . .SH "EXAMPLES" Connect to the server and wait for commands: . .IP "" 4 . .nf cbc subdoc \-u Administrator \-P password \-U couchbase://192\.168\.33\.101/a_bucket subdoc> . .fi . .IP "" 0 . .P Create new document \fBfoo\fR with empty JSON document: . .IP "" 4 . .nf subdoc> upsert foo {} foo CAS=0x14d766f19a720000 . .fi . .IP "" 0 . .P Fetch document with virtual XATTR, containing its metadata: . .IP "" 4 . .nf subdoc> get \-x $document foo foo CAS=0x14d766f19a720000 0\. Size=194, RC=0x00 Success (Not an error) {"CAS":"0x14d766f19a720000","vbucket_uuid":"0x0000ef56295d9206", "seqno":"0x0000000000000021","exptime":0,"value_bytes":2, "datatype":["json","xattr"],"deleted":false,"last_modified":"1501782188"} 1\. Size=2, RC=0x00 Success (Not an error) {} . .fi . .IP "" 0 . .P Increment counter with path \fBsite\.hits\fR twice and set document expiration to 5 seconds\. Note that it sends \fB\-i\fR option to create \fBsite\fR JSON object automatically: . .IP "" 4 . .nf subdoc> counter \-e 5 \-i \-p site\.hits=1 foo foo CAS=0x14d76764f3b60000 0\. Size=1, RC=0x00 Success (Not an error) 1 subdoc> counter \-e 5 \-p site\.hits=1 foo foo CAS=0x14d76765ea2b0000 0\. Size=1, RC=0x00 Success (Not an error) 2 subdoc> get foo foo CAS=0x14d76765ea2b0000 0\. Size=19, RC=0x00 Success (Not an error) {"site":{"hits":2}} \[char46]\[char46]\[char46] wait for 5 seconds \[char46]\[char46]\[char46] subdoc> get foo foo The key does not exist on the server (0xd) . .fi . .IP "" 0 . .P Add into array at path \fBratings\fR value \fB5\fR\. Note, that switch \fB\-u\fR will ask server to create the document if it does not exist: . .IP "" 4 . .nf subdoc> array\-add\-first \-u \-p ratings=5 foo foo CAS=0x14d76814fbb00000 0\. Size=0, RC=0x00 Success (Not an error) subdoc> get foo foo CAS=0x14d76814fbb00000 0\. Size=15, RC=0x00 Success (Not an error) {"ratings":[5]} . .fi . .IP "" 0 . .P Add several objects at once into \fBratings\fR array: . .IP "" 4 . .nf subdoc> array\-add\-last \-p ratings=4,6,7 foo foo CAS=0x14d7687097c50000 0\. Size=0, RC=0x00 Success (Not an error) subdoc> get foo foo CAS=0x14d7687097c50000 0\. Size=21, RC=0x00 Success (Not an error) {"ratings":[5,4,6,7]} . .fi . .IP "" 0 . .P Remove rating with index 2 in array (third number): . .IP "" 4 . .nf subdoc> remove \-p ratings[2] foo foo CAS=0x14d76885efd90000 0\. Size=0, RC=0x00 Success (Not an error) subdoc> get foo foo CAS=0x14d76885efd90000 0\. Size=19, RC=0x00 Success (Not an error) {"ratings":[5,4,7]} . .fi . .IP "" 0 . .P Insert new rating instead of removed one: . .IP "" 4 . .nf subdoc> array\-insert \-p ratings[2]=10 foo foo CAS=0x14d768a6daee0000 0\. Size=0, RC=0x00 Success (Not an error) subdoc> get foo foo CAS=0x14d768a6daee0000 0\. Size=22, RC=0x00 Success (Not an error) {"ratings":[5,4,10,7]} . .fi . .IP "" 0 . .P Fetch number of the items in the \fBratings\fR array: . .IP "" 4 . .nf subdoc> size \-p ratings foo foo CAS=0x14d768a6daee0000 0\. Size=1, RC=0x00 Success (Not an error) 4 . .fi . .IP "" 0 . .P Create document with spaces (surround the value with single quotes, and escape inner single quotes with backslash \fB\e\fR): . .IP "" 4 . .nf subdoc> upsert bar \'{"text": "hello world"}\' bar CAS=0x14d768bc25270000 subdoc> get bar bar CAS=0x14d768bc25270000 0\. Size=23, RC=0x00 Success (Not an error) {"text": "hello world"} . .fi . .IP "" 0 . .SH "TODO" Port tool to Windows platform\. Currently linenoise only supports UNIX\-like systems, but there are unofficial patches for Windows\. . .SH "INTERFACE STABILITY" This command\'s options should be considered uncommitted and are subject to change\. . .SH "SEE ALSO" cbc(1), cbcrc(4), https://developer\.couchbase\.com/documentation/server/current/developer\-guide/sub\-doc\-api\.html . .SH "HISTORY" The \fBcbc\-subdoc\fR tool was first introduced in libcouchbase 2\.7\.7\.