Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the MongoDB CPAN distribution.

Maintainer(s)' notes

Please don't report bugs here. Please use the MongoDB Perl driver issue tracker instead.

Report information
The Basics
Id: 62700
Status: resolved
Priority: 0/
Queue: MongoDB

People
Owner: Nobody in particular
Requestors: abayliss [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: updatedExisting field not returned in last_error after a safe update
Date: Thu, 4 Nov 2010 17:11:06 +0000
To: bug-MongoDB [...] rt.cpan.org
From: Andrew Bayliss <abayliss [...] gmail.com>
When doing an update with upsert and safe set, the updatedExisting field is not returned from a subsequent call to last_error. It is returned if safe is not set. This is using 32 bit Perl 5.10.1, MongoDB module 0.39 and 64 bit Mongo 1.6.2 on 64 bit Linux.
Works as designed. Setting safe=>1 makes the update call last_error. The subsequent call to last_error won't return anything because the previous call was last_error, not an update.
Subject: Re: [rt.cpan.org #62700] Resolved: updatedExisting field not returned in last_error after a safe update
Date: Fri, 19 Nov 2010 16:45:36 +0000
To: bug-MongoDB [...] rt.cpan.org
From: Andrew Bayliss <abayliss [...] gmail.com>
OK, I can understand now why it works as it does, but I still think it's a bug. Even if I want the call to update to return 0 if it fails, I still may want to know if it updated an existing record. I realise I could just not use safe if I might be updating an existing record, but it seems wrong to have to special case this. Either the documentation should change to clarify that you can't get at the updatedExisting field (or any other fields that may be returned by last_error?) if you pass safe => 1 (which isn't really very helpful), or there should be some other way of getting at this data. Andrew
I think the documentation is out of date on CPAN (I'll cut .40 next week) and its behavior is what you're looking for. From http://api.mongodb.org/perl/MongoDB/Collection.html#update%20%28\%25criteria%2c%20\%25object%2c%20\%25options%3f%29: 'Returns 1 unless the safe option is set. If safe is set, this will return a hash of information about the update, including number of documents updated (n). If safe is set and the update fails, update will croak. You can also check if the update succeeded by doing an unsafe update, then calling MongoDB::Database/"last_error($options?)".' (api.mongodb.org/perl updates every time there's a commit.) On Fri Nov 19 11:45:48 2010, abayliss@gmail.com wrote: Show quoted text
> OK, I can understand now why it works as it does, but I still think > it's a bug. Even if I want the call to update to return 0 if it fails, > I still may want to know if it updated an existing record. I realise I > could just not use safe if I might be updating an existing record, but > it seems wrong to have to special case this. > > Either the documentation should change to clarify that you can't get > at the updatedExisting field (or any other fields that may be returned > by last_error?) if you pass safe => 1 (which isn't really very > helpful), or there should be some other way of getting at this data. > > Andrew