Under pymongo the argument is a little different, as in the documentation
ufo.users.remove({'emails.address': 'foo@bar.com'}, safe=True)
And that should do the trick
Question
On python 2.7.3, pymongo 2.7
I am trying to set the justOne safety limiter when removing docs from a pymongo collection.
ufo.users
points to a valid preinitialized collection
>>> type(ufo.users)
<class 'pymongo.collection.Collection'>
>>> ufo.users.remove({'emails.address': 'foo@bar.com'}, {'justOne': True})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/action/.local/lib/python2.7/site-packages/pymongo/collection.py", line 645, in remove
safe, options = self._get_write_mode(safe, **kwargs)
File "/home/action/.local/lib/python2.7/site-packages/pymongo/common.py", line 693, in _get_write_mode
validate_boolean('safe', safe)
File "/home/action/.local/lib/python2.7/site-packages/pymongo/common.py", line 75, in validate_boolean
raise TypeError("Wrong type for %s, value must be a boolean" % (option,))
TypeError: Wrong type for safe, value must be a boolean
Setting the justOne value to 'True','true', 1, or '1' all provide that same error message.
Looking at my the local cache of packages, I found the function in pymongo/common.py
that is supposed to do validation:
def validate_boolean(option, value):
"""Validates that 'value' is 'true' or 'false'.
"""
if isinstance(value, bool):
return value
elif isinstance(value, basestring):
if value not in ('true', 'false'):
raise ConfigurationError("The value of %s must be "
"'true' or 'false'" % (option,))
return value == 'true'
raise TypeError("Wrong type for %s, value must be a boolean" % (option,))
And... I don't get it. I tried passing 'true' and True....
Is this a bug in the package?
What do I need to do to set the justOne option correctly?
Solution
Under pymongo the argument is a little different, as in the documentation
ufo.users.remove({'emails.address': 'foo@bar.com'}, safe=True)
And that should do the trick