dready92 / PHP-on-Couch

Data Access Library to access a CouchDB server with PHP.
http://dready.byethost31.com/index.php/display/view/192
GNU Lesser General Public License v3.0
246 stars 102 forks source link

Create View doc is incorrect #10

Closed couchdbuser2 closed 14 years ago

couchdbuser2 commented 14 years ago

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

dready92 commented 14 years ago

Hello,

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

Regards,

Mickael

couchdbuser2 commented 14 years ago

Thank you for such an easy to use wrapper!

Regards,

SMut commented 13 years ago

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!

SMut commented 13 years ago

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 ;-)