[ chapter top | page top ]
大半のコマンドは次のようなオプションを受け付けます。 各コマンドで実行可能なオプションのリストは"--help"を参照してください。
このオプションは詳細なメッセージを標準エラーに出力します。
このオプションでは標準入力とファイル入力を切り替えることができます。
'-' は標準入力として扱われ、他の文字列は全てファイル名として認識されます。
このオプションでは標準出力とファイル出力を切り替えることができます。
引数はファイル名として認識され、'-'を指定した場合は標準出力として扱われます。
YAML形式の設定ファイル中のラベル名を指定します。デフォルト値は "default.user" です。
CouchDBにアクセスするコマンドのみで有効です。
YAML形式の設定ファイルへのパスを指定します。
CouchDBにアクセスするコマンドのみで有効です。
[ chapter top | page top ]
"mkdb" creates a new database.
$ ./mkdb dbname {"ok":true}
[ chapter top | page top ]
"lsdbs" shows the list of the existing databases.
$ ./lsdbs {"database":[ "_users", "dbname", "test" ]}
[ chapter top | page top ]
"rmdb" deletes the existing database without notice.
$ ./rmdb dbname
[ chapter top | page top ]
"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 {"_id":"65f26940ca75a1a4c3e7c6c64700077f","_rev":"1-0e7d0229c150cae8d724af06e0344b51","name":"yasu","age":"20"} {"_id":"65f26940ca75a1a4c3e7c6c647000791","_rev":"1-ab6f8885ac4a3fa94fb23cb84f6939dc","name":"abe","age":"18"}
[ chapter top | page top ]
"postdocs" is a tool to send a POST request throught the /_bulk_docs interface.
$ echo -e '{"name":"foo"}\n{"name":"bar"}' | ./postdocs test {"failed_list":[]} $ ./lsdocs test {"_id":"65f26940ca75a1a4c3e7c6c64700077f","_rev":"1-0e7d0229c150cae8d724af06e0344b51","name":"yasu","age":"20"} {"_id":"65f26940ca75a1a4c3e7c6c647000791","_rev":"1-ab6f8885ac4a3fa94fb23cb84f6939dc","name":"abe","age":"18"} {"_id":"65f26940ca75a1a4c3e7c6c647001524","_rev":"1-bc98e8ae0f9c89fbc8c237dfc9bfe478","name":"foo"} {"_id":"65f26940ca75a1a4c3e7c6c647001622","_rev":"1-62bc3c4d01e43ee9d0cead8cd7c76041","name":"bar"}
The following commands delete some documents from the "test" database.
$ ./lsdocs test | ./chjson '["_deleted",true]' | ./postdocs test {"failed_list":[]} $ ./lsdocs test $
[ chapter top | page top ]
"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 ]
"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 {"failed_list":[]} $ ./lsviews test all all {"_id":"65f26940ca75a1a4c3e7c6c647002514","_rev":"1-bc98e8ae0f9c89fbc8c237dfc9bfe478","name":"foo"} {"_id":"65f26940ca75a1a4c3e7c6c647003231","_rev":"1-62bc3c4d01e43ee9d0cead8cd7c76041","name":"bar"}
[ chapter top | page top ]
For json stream, YALTools provides some commands like "grep" in unix environment.
"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"]' {"b":{"c":30}} $ echo -e '{"a":"1"}\n{"b":{"c":30}}' | ./grepjson '["b","c",30]' {"b":{"c":30}}
[ chapter top | page top ]
"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":"65f26940ca75a1a4c3e7c6c647002514","_rev":"1-bc98e8ae0f9c89fbc8c237dfc9bfe478","name":"foo","_deleted":true} {"_id":"65f26940ca75a1a4c3e7c6c647003231","_rev":"1-62bc3c4d01e43ee9d0cead8cd7c76041","name":"bar","_deleted":true} {"_id":"_design/all","_rev":"17-a29e5cc677328801f05a869f76a2f0f4","views":{"all":{"map":"function(doc) { emit(doc._id,null); }"}},"_deleted":true}
[ chapter top | page top ]
"reducejson" pulls out some key-value pairs to construct new json line.
$ echo '{"_id":"xxx","_rev":"yyy","name":"zzz"}' | ./reducejson '["_id","name"]' {"_id":"xxx","name":"zzz"}
"reducejson -e" removes key-value pairs from the given list.
$ echo '{"_id":"xxx","_rev":"yyy","name":"zzz"}' | ./reducejson -e '["_rev"]' {"_id":"xxx","name":"zzz"}
[ chapter top | page top ]
"jsonfmt" reads each line from stdin or a file and pass it to YALTools::JsonFormatter#parse module method.
[ chapter top | page top ]
"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"]}
The "-n" options is available for the intuitive behavior.
$ echo -e "key1,key2\nval1,val2\nval3,val4" | bin/csv2json {"key1":["val1","val3"],"key2":["val2","val4"]} $ echo -e "key1,key2\nval1,val2\nval3,val4" | bin/csv2json -n {"key1":"val1","key2":"val2"} {"key1":"val3","key2":"val4"}
[ chapter top | page top ]
"lsdoc" is a tool to send a GET request to CouchDB.
$ bin/lsdoc /test/_security {"admin":{"names":[""],"roles":["fwadmin","fwwriter"]},"reader":{"names":[""],"roles":["fwreader"]}}
[ chapter top | page top ]
"putdoc" is a tool to send a PUT request to CouchDB.
[ chapter top | page top ]
"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 {"ok":true}
[ chapter top | page top ]
"senduri" shows the result of the request using the YAML configuration file.
$ ./senduri /test/_all_docs
[ chapter top | page top ]
"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 ]
Created: 2011-03-01T14:59:23+09:00
Last modified: 2011-03-13T21:56:01+09:00
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.