简体   繁体   English

对 ObjectId 字段的 Atlas 搜索不起作用

[英]Atlas search on an ObjectId field doesn't work

I was trying to implement an Atlas search query on an ObjectId field but nothing is being matched.我试图在 ObjectId 字段上实现 Atlas 搜索查询,但没有匹配。 Here's the index definition.这是索引定义。

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "hscode": {
        "foldDiacritics": true,
        "maxGrams": 4,
        "minGrams": 1,
        "tokenization": "edgeGram",
        "type": "autocomplete"
      },
      "title": {
        "foldDiacritics": true,
        "maxGrams": 10,
        "minGrams": 2,
        "tokenization": "edgeGram",
        "type": "autocomplete"
      },
      "type._id": {
        "type": "objectId"
      }
    }
  }
}

The query details are as follows查询详情如下

db.categories.aggregate([
    {
        $search:{
            index:"categorySearch",
            equals:{
                path:"type._id",
                value:ObjectId("61711b4275e9397ec79bdfed")
            }
        }
    }
])

Note : The autocomplete queries are working without a problem.注意:自动完成查询工作正常。 Thanking you in advance.提前谢谢你。

For those who are facing this issue, change the dot notation in the index definition to an object.对于那些面临此问题的人,请将索引定义中的点表示法更改为对象。 So,所以,

type._id:{type:ObjectId()}

should be changed to应该改为

type:{_id:{type:ObjectId()}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM