Here is a document(name is Word) example:
{
"id":"xxxxxxxx",
"words":["hello","world","cat","dog","word1","word2"]
}
now I have a word list contains some words, for example:
["friend","hello","world","stack","question"]
I have 2 operation (Every time I will do one of them, not all of them): 1. PUSH. I want to push all the new word into array, in this case ,the word is "friend","stack","question". "hello" and "world" is already exist, I will not push them in. 2. PULL. I want to pull some word already exist in words, in this case I want to pull "hello" and "world" out.
One way I know is to do a for loop, but it seems awful. Can I meet what I need in 1 update operation? such as collection.update(query,op)
.
I am using flask-MongoEngine and also pymongo operation is also supported.