使用连字符时如何避免否定?

How to avoid negation while using hyphen?

我的查询类似于:

db.mycollection.find({
     $text: {
        $search: "my -city"
     }
})

如果我运行这个查询,它会否定city。但我想搜索确切的短语 my -city。我该怎么做?

要搜索的文本可以是 my-citymy - citymy -city。有没有一种方法可以指示 mongodb 不使用否定作为默认行为,而只使用精确的字符串匹配?

尝试像这样用 \" ... \" 包装它

db.mycollection.find({
     $text: {
        $search: "\"my -city\""
     }
})