MongoEngine remove string from ListField MongoEngine remove string from ListField flask flask

MongoEngine remove string from ListField


If you want to remove one element from your list you need to use the pull modifier which takes a single value not a list as you are doing so the correct query is:

Users.objects(username='some_user').update(pull__following='some_string')

You can also remove several element from your "following" list using the pull_all modifier; and in this case you pass in a list of value.

Users.objects(username='some_user').update(pull_all__following=['one_string', 'another_string'])