I’m using Python in conjunction with MongoDB. I have an array of words, and I use these words to search the Mongo database and match any documents with matching fields using $in, e.g.
collection.find({"word":{"$in":words}})
The above works very well, but I want to be able to use a regex. The problem is now that if one of the words in the array was spelt accus instead of accuse, I want the find() query to still return the document (record/row) relating to the word accuse.
I’ve tried this, which doens’t work at all, no results are returned.
collection.find({"word":{"$in":{"$regex":words}}})
Each element in the array reads with ^ preceding the word,
e.g. ['^work', '^accus', '^planet']
Am I just going about this the wrong way?
Sorry for late answer, just googled your question. You should use one regex, not an array of them, like: