1. Command Reference

1-1. Overview

YALTools Commands Overview

[ chapter top | page top ]

1-2. Common options

Most of commands have the following options.

1-2-1. -h: Showing help messages

This option shows the all available options.

$ ./lsdocs --help
  Usage: lsdocs dbname [-p page] [-u unit] [-i] [-d] [-y] [-x]

    -i, --show_index                 Display ["id","key","value"] tags only
    -u, --unit num_of_unit           Set the num of processing unit (default: 15)
    -p, --page page                  Set the num of pages (default: 1)
    -r, --reverse                    Enable reverse mode
    -m, --max_numrows                Enable max_numrows mode
    -o, --outfile outfile            Set output filename or '-'.
    -y, --yaml_conf filename         Set yaml conf file
    -x, --yml_label label            Set label name in the yaml conf file
    -d, --debug                      Enable the debug mode
    -h, --help                       Show this message

1-2-2. -d: Turning on debug mode

This option turns on the debug message output.

1-2-3. -f filename: Input filename (default: '-')

If the command inputs something from the stream, you can toggle stdin and file by this option.

The '-' value means the standard input, others are used as a filename.

1-2-4. -o filename: Output filename (default: '-')

If the command outputs something to the stream, you can toggle stdout and file by this option.

The '-' value means the standard output, others are used as a filename which will be overwritten.

1-2-5. -x label_name: Config label name

If the command uses the YAML configuration file, you can specify the label name by this option.

The default value is default.user. It depends on the access requirement of each command.

This option is only available on the command which access to CouchDB.

1-2-6. -y filename: Config filename

If the command uses the YAML configuration file, you can set the path of the YAML file by this option.

The path should be the absolute path or relative path from the current directory.

This option is only available on the command which access to CouchDB.

[ chapter top | page top ]

2. Commands for DB Admins

2-1. sbin/mkdb

"mkdb" creates a new database.

$ ./mkdb dbname

[ chapter top | page top ]

2-2. sbin/lsdb

"lsdbs" shows the list of the existing databases.

$ ./lsdbs

[ chapter top | page top ]

2-3. sbin/rmdb

"rmdb" deletes the existing database without notice.

$ ./rmdb dbname

[ chapter top | page top ]

3. Commands for Documents

3-1. bin/lsdocs

"lsdocs" sends a GET request and shows all documents through the /dbname/_all_docs interface.

To optimize performance, "lsdocs" uses skip and limit parameters in the internal processing.

$ ./lsdocs test

3-1-1. -u number: set the number of proceesing unit (default: 15)

"lsdocs" outputs result lines by each specified number.

The bigger number might cause an ineffective performance.

3-1-2. -p number: set the specified page number.

To show only the specified page, the page number should be greater than one.

Zero means to show all pages.

[ chapter top | page top ]

3-2. bin/postdocs

"postdocs" is a tool to send a POST request throught the /_bulk_docs interface.

$ echo -e '{"name":"foo"}\n{"name":"bar"}' | ./postdocs test
$ ./lsdocs test

The following commands delete some documents from the "test" database.

$ ./lsdocs test | ./chjson '["_deleted",true]' | ./postdocs test
$ ./lsdocs test

[ chapter top | page top ]

4. Commands for Views

4-1. bin/putdesign

"putdesign" takes the two arguments, dbname and docname, and puts reading data into the given path, /dbname/_design/docname.

$ echo '{"views":{"all":{"map":"function(doc) { emit(doc._id,null); }"}}}' | ./putdesign test all

[ chapter top | page top ]

4-2. bin/lsviews

"lsviews" shows all documents of the specified view.

After executing the example of "putdesign" to the empty "test" database, following commands show the result of "lsviews."

$ echo -e '{"name":"foo"}\n{"name":"bar"}' | ./postdocs test
$ ./lsviews test all all

[ chapter top | page top ]

5. Commands for JSON Stream

For json stream, YALTools provides some commands like "grep" in unix environment.

5-1. bin/grepjson

"grepjson" searches the inputs for lines containing specified condition.

The condition is JSON arrays and specified by an array, such as ["key1","key2",...,"value"].

$ echo -e '{"a":"1"}\n{"b":{"c":30}}' | ./grepjson '["b","c"]'
$ echo -e '{"a":"1"}\n{"b":{"c":30}}' | ./grepjson '["b","c",30]'

[ chapter top | page top ]

5-2. bin/chjson

"chjson" adds or overwrites the given key-value pair into each line.

The following command line will add the delete flag for /_bulk_docs api.

$ ./lsdocs test | ./chjson '["_deleted",true]'
{"_id":"_design/all","_rev":"17-a29e5cc677328801f05a869f76a2f0f4","views":{"all":{"map":"function(doc) { emit(doc._id,null); }"}},"_deleted":true}

[ chapter top | page top ]

5-3. bin/reducejson

"reducejson" pulls out some key-value pairs to construct new json line.

$ echo '{"_id":"xxx","_rev":"yyy","name":"zzz"}' | ./reducejson '["_id","name"]'

5-3-1. -e: exclude option

"reducejson -e" removes key-value pairs from the given list.

$ echo '{"_id":"xxx","_rev":"yyy","name":"zzz"}' | ./reducejson -e '["_rev"]'

[ chapter top | page top ]

5-4. bin/jsonfmt

The "jsonfmt" transforms the input JSON stream into a human readable text.

It reads each line from stdin or a file and pass it to YALTools::JsonFormatter#parse module method.

$ bin/lsdoc /
$ bin/lsdoc / | bin/jsonfmt
  "couchdb":  "Welcome",
  "version":  "1.0.2"

[ chapter top | page top ]

5-5. bin/csv2json

"csv2json" is a tool to parse a csv file and produce json format string.

However, this command is not well-known csv2json script. There are some unique rules for the transformation.

## rule 1.
    | key1 | key2 | 
    |=============|  => key1:val1,key2:val2
    | val1 | val2 |
    $ echo -e "key1,key2\nval1,val2" | bin/csv2json
    > {"key1":"val1","key2":"val2"}
## rule 2.
    | key1 | key2 | 
    |=============|   => key1:{key2:val1}
    |      | val1 |

    $ echo -e "key1,key2\n,val2" | bin/csv2json
    > {"key1":{"key2":"val2"}}
## rule 3.
    | key1 | 
    | val1 |   => key1:[val1,val2]
    | val2 |
    $ echo -e "key1\nval1\nval2" | bin/csv2json
    > {"key1":["val1","val2"]}

5-5-1. -s spliter: set the delimiter string (default: ',')

The "-s spliter" option changes the delimiter string.

5-5-2. -n: normal operation mode option

The "-n" options is available for the intuitive behavior.

$ echo -e "key1,key2\nval1,val2\nval3,val4" | bin/csv2json 
$ echo -e "key1,key2\nval1,val2\nval3,val4" | bin/csv2json -n

[ chapter top | page top ]

6. Misc. Commands

6-1. bin/lsdoc

"lsdoc" is a tool to send a GET request to CouchDB.

$ bin/lsdoc /test/_security

[ chapter top | page top ]

6-2. bin/putdoc

"putdoc" is a tool to send a PUT request to CouchDB.

[ chapter top | page top ]

6-3. bin/postdoc

"postdoc" is a tool to send a PUT request to CouchDB.

The functionality is same as the "putdoc" command.

The POST request is required to create "_id" less document and required for replication and compaction in CouchDB.
$ bin/postdoc /test/_compact < /dev/null

[ chapter top | page top ]

6-4. sbin/senduri

"senduri" shows the result of the request using the YAML configuration file.

$ ./senduri /test/_all_docs

[ chapter top | page top ]

6-5. sbin/sendurl

"sendurl" shows the result of the request by the URL.

It does not use the YAML configuration file.

./sendurl http://localhost:5984/_all_dbs

[ chapter top | page top ]

7. Configuration Files

The YAML configuration file, utils/conf/yalt.yaml, is the main configuration file.

Please refer the all available options at the YALTools::MainWrapper API documents.

7-1. The yalt.conf file format

A minimum setting was explained at the Installation section.

The file format for basic and digest authentications is the following.

    password_salt:       ## option for encrypted password.
    password_pass_file:  ## option.
    digest_auth:         ## option for digest_auth.
    cacert:              ## option for ssl.
The net-http-digest_auth library is required for the digest auth.
    $ sudo gem install net-http-digest_auth

If you want to use an encrypted password, the encrypted text should be produced by the following method.

$ sbin/encpassword -p password
password_salt: 69fc92a2725fa2d0
password: c07b612f149f82afeb4fb762d98be8cf

After that, please copy password_salt: and password: lines into the yalt.yaml file.

    port: 5984
    user: admin
    password_salt: 69fc92a2725fa2d0
    password: c07b612f149f82afeb4fb762d98be8cf
Before use the encpassword command, to set up the master_pw.json is required.
Please refer the Install instructions at Getting tarted page.

7-1-1. Basic authentication

The basic authentication is the most typical case, and most of user needs the following lines at the utils/conf/yalt.yaml file.

    port: 5984
    user: admin
    password: xxxx

7-1-2. Digest authentication

CouchDB does not have the diegst authentication feature, but it can be used to place a reverse proxy server in front of CouchDB.

To enable the digest authentication, it just adds the "digest_auth" key to the yalt.yaml file.

    port: 5984
    user: admin
    password: xxxx
    digest_auth: ""

It just needs the "digest_auth" key, so any value of the "digest_auth" enables the authentication.

[ chapter top | page top ]

Permalink: /1.0/commands.html

Created: 2011-03-01T13:41:29+09:00
Last modified: 2011-03-15T01:05:34+09:00

lscouchdb.sourceforge.net / 2011 © Yasuhiro ABE <yasu@yasundial.org> JabberID: yadiary@jabber.org

Valid XHTML + RDFa 正当なCSSです!
RDFa it (RDF/XML)!

Creative Commons License lscouchdb.sourceforge.net by Yasuhiro ABE is licensed under a Creative Commons Attribution 2.1 Japan License. Permissions beyond the scope of this license may be available at http://lscouchdb.sourceforge.net/license.html.