joshmarshall/mogo — Issue #13: Model.remove() is too dangerous by default
Author: joshmarshall
Created: 2012-03-02 02:46:10+00:00
State: open

Currently, Model.remove(*args, **kwargs) passes directly to pymongo.db.collection.remove(*args, **kwargs). Even though it follows Mogo's basic requirement of being "nearly transparent" for the pymongo driver, it is far too dangerous by default. For example:

"""python
# the following three statements remove ALL entries from the collection
FooModel.remove()
FooModel.remove({})
FooModel.remove(value="foo")
"""

The third example is even more insidious, in that a user, accidentally using keyword arguments instead of a {} query, will wipe the collection without knowing it.

Just as @JeffMcGee updated find() and find_one() to throw an Exception if there is no search query, we should update remove() so that it throws an Exception if there are no positional arguments.