dready92 / PHP-on-Couch

Data Access Library to access a CouchDB server with PHP.

Home Page:http://dready.byethost31.com/index.php/display/view/192

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create View doc is incorrect

couchdbuser2 opened this issue · comments

Hi,

I read http://github.com/dready92/PHP-on-Couch/blob/master/doc/couch_client-view.md to create a view but the section:

$view_fn="function(doc) { emit(doc.timestamp,null); }";
$design_doc->_id = '_design/all';
$design_doc->language = 'javascript';
$design_doc->views = array ( 'by_date',$view_fn);
$client->storeDoc($design_doc);

should be:

$view_fn="function(doc) { emit(doc.timestamp,null); }";
$design_doc->_id = '_design/all';
$design_doc->language = 'javascript';
$design_doc->views = array ( 'by_date' => 'map' => $view_fn);
$client->storeDoc($design_doc);

otherwise it will not really create a view

Hello,

You're perfectly right. Thank you to report this error to me. Commit e60a901 fixed the bug.

Regards,

Mickael

Thank you for such an easy to use wrapper!

Regards,

thanks couchdbuser2 for the patch. as I am a newbie to couchDB I got stuck.: a database without getting results is useless. you made my day! merry Xmas by the way!

Phew, this issue really popped me out of my socks. couchdbuser2 had some nice bugs in it:
$design_doc->id = 'design/all';
id needs an underscore: _id

$design_doc->views = array ( 'by_date' => 'map' => $view_fn); $client->storeDoc($design_doc);

This one won't work (at least with my php version), you have to define map as an array.

here is my version (tested on a couchdb -v 0.10.0 lighttpd 1.4.26 PHP 5.3.2)
$design_doc->_id = 'design/all';
$design_doc->language = 'javascript';
$view_fn=array( 'map' => 'function(doc) { emit(doc.timestamp,null); }');
$design_doc->views = array ( 'by_date' => $view_fn );
$client->storeDoc($design_doc);
This one works and shows this sourceview in futon:
{
"_id": "design/all",
"_rev": "1-fa2ce68ff2bc648c92ff0502f44e8adb",
"language": "javascript",
"views": {
"by_date": {
"map": "function(doc) { emit(doc.timestamp,null); }"
}
}
}
This is fine.
(PHP hates me, but it's okay ;-)