in reply to Retrieving content from couchdb using CouchDB::Client

Is there a way to determine if newDoc might have failed to create the document? What is the result of running the following?

use warnings; use CouchDB::Client; my $c = CouchDB::Client->new(uri => 'http://127.0.0.1:5984/'); my $db = $c->newDB('test'); my ($doc) if ($db->docExists('12345')) { print "hello\n"; } else { $doc = $db->newDoc('12345', undef, {'foo'=>'bar'})->create; } print $doc->retrieve('12345');
Dum Spiro Spero

Replies are listed 'Best First'.
Re^2: Retrieving content from couchdb using CouchDB::Client
by shivam99aa (Novice) on Apr 23, 2015 at 15:39 UTC

    CouchDB::Client::Doc=HASH(0x240e8e8)

    This is what i get in return, my point is that i created a document and then i am able to get it since $doc object is present but if the doc is present already in couchdb and i want to retrieve it then what should be the procedure. If i run the same code again then doc is already present in couchdb so i get this as output.

    hello

    Can't call method "retrieve" on an undefined value at couch.pl line 15.

      Perhaps apply the retrieve method to the $db object?

      if ($db->docExists('12345')) { print "hello\n"; $doc = $db->retrieve('12345'); } else { $doc = $db->newDoc('12345', undef, {'foo'=>'bar'})->create; }
      Dum Spiro Spero

        get the same result as previously

        hello

        Can't call method "retrieve" on an undefined value at couch.pl line 11.