MongoDB 3.4
我有一个变量val1 = "Fort Minor"。
我需要在一个名为stores的集合中搜索(该集合在name字段上具有文本索引),其中包含以下文档:
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" }
])
当我使用变量进行集合文本搜索时
db.City.find({$text:{$search: val1}})
它返回了_id为4的文档,因为它包含Fort。
我需要进行精确匹配,但是要使用变量。
上面的搜索应该仅在val1 =“Fort Coffee”时返回。