MongoDB 3.4
I have a value in a variable. val1 = "Fort Minor"
I need to search in a collection stores (with text index on name field) with documents as
db.stores.insert([
{ _id: 1, name: "Java Hut", description: "Coffee and cakes" },
{ _id: 2, name: "Burger Buns", description: "Gourmet hamburgers" },
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },
{ _id: 4, name: "Fort Coffee", description: "Discount clothing" },
{ _id: 5, name: "Java Shopping", description: "Indonesian goods" }
])
when I text search the collection using the variable
db.City.find({$text:{$search: val1}})
it returns the _id : 4 document, since it contains Fort.
I need to do an exact match but using the variable.
The above search should return only when val1 = "Fort Coffee"