在MongoDB"db.foo.find()"语法中,如何让它匹配所有字母及其重音版本?

例如,如果我的数据库中有一个姓名列表:

How would I allow a search for the strings "Joao", "Francois", or "Jesus" to match the given name?
I am hoping that I don't have to do a search like this every time:
db.names.find({name : /Fr[aã...][nñ][cç][all accented o characters][all accented i characters]s/ })

推荐答案

从Mongo 3.2开始,您可以使用$text并将$diacriticSensitive设置为false:

{
  $text:
    {
      $search: <string>,
      $language: <string>,
      $caseSensitive: <boolean>,
      $diacriticSensitive: <boolean>
    }
}

更多信息请参见Mongo文档:https://docs.mongodb.com/manual/reference/operator/query/text/

Mongodb相关问答推荐

MongoDB索引使用

为什么数组长度0被认为是Mongoose中排序中最大的数字

如何在 mongodb 中将一个方面的结果合并到一个有条件的列表中?

对 MongoDB 集合中的对象数组进行排序

根据聚合管道MongoDB Atlas触发器中的条件更新多个字段

在MongoDb的数组中计算大于某个数字的数字

MongoDB查询仅返回嵌入文档

使用 Node.js 通过 SSL 连接到 MongoDB

使用 MongoDb 处理迁移

在 Heroku 上使用 Node 读取、写入和存储 JSON

Node.js 数据库的抽象层

mongodb,pymongo,aggregate聚合给出奇怪的输出

嵌套在文档数组中的mongodb展开数组

Mongoose 是否真的验证了对象 ID 的存在?

如何获取 Mongoid 文档的所有字段名称?

MongoDB - 我如何找到另一个集合中的文档未引用的所有文档

遍历所有 Mongo 数据库

mongodb 的计数性能

初创公司应该考虑哪些数据库系统?

MongoMapper 和迁移