Reputation: 566
I have a users collection in pymongo and flask and inside the users collection I have the field "ratings":[] which takes items as input and appends them inside the list . I'm a beginner in pymongo and flask and I have trouble deleting a specific item inside the ratings list . Let's say that I have a user instance like :
user = users.find_one({"name":"Bill" , "ratings":["good" , "bad"]})
Using :
user['ratings'].remove("bad")
returns TypeError: string indices must be integers
How can I delete the "bad" item inside the ratings list and what does this error mean? I would appreciate your guidance with helping me with this task . Thank you in advance
Upvotes: 0
Views: 107
Reputation: 5058
You should use the $pull
operator.
db.collection.update(
{ name: 'Bill' },
{ $pull:
{ ratings: 'bad' }
}
)
Upvotes: 2
Reputation: 566
SOLVED : users.update_one({"Email":email} , {"$pull":{"ratings":rating} })
did the job and deleted the user
Upvotes: 0