I was trying to implement an Atlas search query on an ObjectId field but nothing is being matched. 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()}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.