how to search for a substring in MongoDB which starts with +

Viewed 24

From a mongoDB collection I wanted to search the document for which the name field has substring "+Ava"(substring starting with +). Tried it by using regex but it was giving following error: "errmsg" : "Regular expression is invalid: nothing to repeat"

Query made : db.employees.find({name:{$regex : "+ava", $options: 'i'}})

Also tried this query but it also gave the same error db.employees.find({name:/+ava/})

1 Answers

+ is a special character, you just need to escape it, like so:

db.employees.find({name:/\+ava/})
Related