avsej
February 27, 2013, 12:02am
1
I recommend you to take a look at cbc tool and see how does it create buckets
lcb_CMDPING cmd = { 0 };
lcb_error_t err;
cmd.services = LCB_PINGSVC_F_KV | LCB_PINGSVC_F_N1QL | LCB_PINGSVC_F_VIEWS | LCB_PINGSVC_F_FTS;
cmd.options = LCB_PINGOPT_F_JSON | LCB_PINGOPT_F_JSONPRETTY;
if (o_details.passed()) {
cmd.options |= LCB_PINGOPT_F_JSONDETAILS;
}
lcb_sched_enter(instance);
err = lcb_ping3(instance, NULL, &cmd);
if (err != LCB_SUCCESS) {
throw LcbError(err);
}
lcb_sched_leave(instance);
lcb_wait(instance);
}
void
McFlushHandler::run()
{
Handler::run();
To save design document you should make PUT request with your design document in JSON format, the command payload will look like this:
const char *docid = “_design/test”;
const char *doc = “{“views”:{“all”:{“map”:“function (doc, meta) { emit(meta.id , null); }”}}}”;
lcb_http_cmd_t cmd;
cmd.version = 0;
cmd.v.v0.path = docid;
cmd.v.v0.npath = strlen(docid);
cmd.v.v0.body = doc;
cmd.v.v0.nbody = strlen(doc);
cmd.v.v0.method = LCB_HTTP_METHOD_PUT;
cmd.v.v0.content_type = “application/json”;
rc = lcb_make_http_request(instance, NULL, LCB_HTTP_TYPE_VIEW, &cmd, NULL);
avsej
February 27, 2013, 12:03am
2
Also I’ve made update in the man file with the example above, so it will be documented in next releases
http://review.couchbase.org/#/c/24892/
swapmat
February 27, 2013, 12:03am
3
Thanks. I was using the yajl example and it was failing.
$ ./couchview -b beer-sample _design/country -d '{ "id" : "_design/country", "language" : "javascript", "views" : { "country" : { "map" : "function(doc) { if (doc.country) { emit(doc.country, 1) } }" } } }'
Server: MochiWeb/1.0 (Any of you quaids got a smint?)
Date: Wed, 27 Feb 2013 09:46:51 GMT
Content-Type: application/json
Content-Length: 80
Cache-Control: must-revalidate
Allow: DELETE,GET,HEAD,POST,PUT
"_design/country": OK
{
"error": "method_not_allowed",
"reason": "Only DELETE,GET,HEAD,POST,PUT allowed"
}
I changed the POST to PUT and it worked.
./couchview -b beer-sample _design/country -d '{ "id" : "_design/country", "language" : "javascript", "views" : { "country" : { "map" : "function(doc) { if (doc.country) { emit(doc.country, 1) } }" } } }'
Server: MochiWeb/1.0 (Any of you quaids got a smint?)
Location: http://127.0.0.1:8092/beer-sample/_design/country
Date: Wed, 27 Feb 2013 09:50:54 GMT
Content-Type: application/json
Content-Length: 35
Cache-Control: must-revalidate
"_design/country": OK
{
"ok": true,
"id": "_design/country"
}
avsej
February 27, 2013, 12:08am
4
If you have libcouchbase2-bin package installed (it includes cbc CLI tool), you can also use ‘cbc view’ for it. ‘cbc view’ actually re-implementation of couchview but in user-land tool.
cbc view -X PUT -b beer-sample _design/country -d ‘{“id”:"_design/country",“language”:“javascript”,“views”:{“country”:{“map”:“function(doc){ if (doc.country) { emit(doc.country, 1) } }”}}}’
swapmat
February 27, 2013, 12:08am
5
Hi,
Can anyone point me to example code to create views using lcb_make_http_request?
I checked example/yajl/couchview.c but unfortunately I can’t understand how to create views.
Thanks
jygan
May 20, 2013, 11:10pm
6
how to install libcouchbase 2-bin package redhat linux? i cannot find this package thanks!
avsej
May 21, 2013, 11:05pm
7
in the same way how you are installing others. list all libcouchbase packages:
$ yum search libcouchbase
…snip…
libcouchbase-debuginfo.i686 : Debug information for package libcouchbase
libcouchbase-devel.i686 : Couchbase Client & Protocol Library - Header files
libcouchbase1.i686 : Couchbase Client & Protocol Library
libcouchbase1-bin.i686 : Couchbase Client Tools
libcouchbase2.i686 : Couchbase Client & Protocol Library
libcouchbase2-bin.i686 : Couchbase Client Tools
libcouchbase2-core.i686 : Couchbase Client & Protocol Library (core)
libcouchbase2-libev.i686 : Couchbase Client & Protocol Library (libev backend)
libcouchbase2-libevent.i686 : Couchbase Client & Protocol Library (libevent backend)
and then install what you need
$ sudo yum install libcouchbase2-bin
Damian
October 1, 2013, 7:08pm
8
Yes, changing in couchbase.c line 471 to PUT seems to make it work
cmd.v.v0.method = bytes ? LCB_HTTP_METHOD_PUT : LCB_HTTP_METHOD_GET;
Damian
October 1, 2013, 7:17pm
9
Sorry I meant couchview.c