首页 > 解决方案 > 带有 & 的 MongoDB 搜索查询

问题描述

我的文档具有如下所示的结构。

{ 
  id: '2eacea29-915c-4573-91c3-98815143b722',
  name: 'hey look at all this &'
}

我已经尝试执行搜索查询db.myCollection.find({"$text" : {"$search" : "\"\&\""}})。但结果为空。怎么了?

标签: mongodbmongoosemongodb-query

解决方案


尝试使用$regex.

db.collection.find({
  "name": {
    "$regex": "&"
  }
})

这是工作演示:https ://mongoplayground.net/p/CBVBH1HYcJx


推荐阅读