Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use remove()? #36

Open
holms opened this issue May 2, 2014 · 0 comments
Open

How to use remove()? #36

holms opened this issue May 2, 2014 · 0 comments

Comments

@holms
Copy link

holms commented May 2, 2014

This is not really issue, but a question. I'm seriously confused, or I'm getting old.. Through all documentation I've found about MongoAlchemy and flask-mongoalchemy, I just don't understand how to remove from DB something simple as for example this:

class User(db.Document):
    username      = db.StringField()
    password_hash = db.HashField()

and let's say there's already one row in db where username is 'holms'.
How can I remove it?? I mean completely delete whole row with password_hash too. In real system I usually avoid to remove users, but this is for unit testing.

My attempt:

 users = User.query.filter(User.username=="holms")

----> 1 users.remove_all(User.username, ['holms'])

/var/www/msgapp/backend/lib/python2.7/site-packages/mongoalchemy/query.pyc in remove_all(self, qfield, *value)
    387     def remove_all(self, qfield, *value):
    388         ''' Refer to:  :func:`~mongoalchemy.update_expression.UpdateExpression.remove_all`'''
--> 389         return UpdateExpression(self).remove_all(qfield, *value)
    390
    391     def add_to_set(self, qfield, value):

/var/www/msgapp/backend/lib/python2.7/site-packages/mongoalchemy/update_expression.pyc in remove_all(self, qfield, *value)
    123     def remove_all(self, qfield, *value):
    124         ''' Atomically remove each value in ``value`` from ``qfield``'''
--> 125         return self._atomic_list_op_multivalue('$pullAll', qfield, *value)
    126
    127     def add_to_set(self, qfield, value):

/var/www/msgapp/backend/lib/python2.7/site-packages/mongoalchemy/update_expression.pyc in _atomic_list_op_multivalue(self, op, qfield, *value)
    147         qfield = resolve_name(self.query.type, qfield)
    148         if op not in qfield.valid_modifiers:
--> 149             raise InvalidModifierException(qfield, op)
    150         wrapped = []
    151         for v in value:

InvalidModifierException: Invalid modifier for QueryField field: $pullAll

users = User.query.filter(User.username=='holms')
users.remove()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-74-4b66f4960b06> in <module>()
----> 1 users.remove()

TypeError: remove() takes exactly 3 arguments (1 given)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant