Details
-
Task
-
Resolution: Unresolved
-
Minor - P4
-
None
-
None
-
None
-
Developer Tools
Description
When creating a Search index, you can't use the dot syntax to access to a field in an object inside an array. For example, take the following document into consideration:
{
|
"movie": "Barbie", |
"topReviews": [ |
{ "score": 10, "review": "I'm just Ken" } |
]
|
}
|
If we want to create an index so we can search top reviews by text, it would be reasonable to try to define an index like this:
{
|
"mappings": { |
"fields": { |
"topReviews.review": { |
"type": "string" |
}
|
}
|
}
|
}
|
However, as review is an object inside an array of topReviews, this is not possible. We need to use the embeddedDocs type:
{
|
"mappings": { |
"fields": { |
"topReviews": { |
"type": "embeddedDocument", "fields": { "review": { "type": "string" } } |
}
|
}
|
}
|
}
|
The autocomplete should be aware of the type of the document tree so it doesn't autocomplete with invalid index definitions.
More documentation:
- https://www.mongodb.com/docs/atlas/atlas-search/field-types/embedded-documents-type/#std-label-bson-data-types-embedded-documents
- https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/