سؤال

I'm trying to figure out how to check if an update succeeded. By default, does db.users.update(....) return a getLastError type? So can I do something like:

error = db.users.update(.....)
if error.n == 1:
  ....

How can I check to make sure that the update succeeded?

هل كانت مفيدة؟

المحلول

pymongo's vague docs say update's return value is:

A document (dict) describing the effect of the update or None if write acknowledgement is disabled.

(Not explicitly stated but) this means that the return value is lastError (unless you use safe=True).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top