I am using pymongo and want to search for elements starting with a specific sequence of characters. I could implement this as follows:
items = collection.find({ 'key': '/^text/' })
This should work, but what if text is a variable? I could do something like:
items = collection.find({ 'key': '/^' + variable + '/' })
But now, if the text in variable contains any characters with a special regular expression value (for example, $ ), the query no longer behaves as expected. Is there a way to do parameter binding? Do I need to sanitize a variable own? Is it possible to do this?
Thanks!
source share