Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-249

Collection.update(safe=True) behavior inconsistent

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.11
    • Component/s: None
    • Labels:
      None
    • Environment:
      wherever

      Documentation says that when passing safe=True to update(), the return value will be the result of getLastError. This is only partially true. It is the result of getLastError, if getLastError has a non-0 'err' field in the return. Otherwise, it returns None. The issue is that getLastError also returns other useful information: in my case, I was trying to use the "updatedExisting" field from that response. I ended up having to use Database.command('getlasterror') to get it, because even Database.error() has identical semantics to update(), in that it returns nothing without a true "error" result (quick code dive confirms this behavior).

      At the very least, documentation should be updated to indicate that the getlasterror detail is only returned in some cases, at best it would always be returned, and alternately there'd be a first-class way of checking "updatedExisting" from that result in the specific case of an update.

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            kiril Kiril Savino
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: