Docs Menu

Docs HomeMongoDB Atlas

embeddedDocument

On this page

  • Definition
  • Syntax
  • Options
  • Behavior
  • Limitations
  • Examples

Note

The Atlas Search embeddedDocuments index option, embeddedDocument operator, and embedded scoring option are in preview. When an Atlas Search index on a replica set or single MongoDB shard reaches Lucene’s two billion document limit, Atlas Search doesn't index new documents or apply updates to existing documents for that index. A solution to accomodate this limitation will be in place when we make this feature generally available. Meanwhile, the MongoDB Cloud Support team will help troubleshoot any issues related to using this feature as part of your contract.

embeddedDocument

The embeddedDocument operator is similar to $elemMatch operator. It constrains multiple query predicates to be satisfied from a single element of an array of embedded documents. embeddedDocument can be used only for queries over fields of type embeddedDocuments.

embeddedDocument has the following syntax:

{
"embeddedDocument": {
"path": "<path-to-field>",
"operator": { <operator-specification> },
"score": { <score-options> }
}
}

embeddedDocument uses the following options to construct a query:

Field
Type
Description
Necessity
operator
object
Operator to use to query each document in the array of documents that you specify in the path.
Required
path
string
Indexed embeddedDocuments type field to search. The specified field must be a parent for all operators and fields specified using the operator option. See Path Construction for more information.
Required
score
object
Score to assign to matching search results. You can use the embedded scoring option to configure scoring options. If you omit this option or use another scoring option, embeddedDocument operator uses the default aggregation strategy, sum, for combining scores of embedded document matches. To learn more, see Customize and Normalize the Score in Results.
Optional

When you query embedded documents in arrays using the embeddedDocument operator, Atlas Search evaluates and scores the operator query predicates at different stages of query execution. Atlas Search:

  1. Evaluates each embedded document in the array independently.

  2. Combines the scores of matching results as configured using the embedded option, or scores by summing the scores of matching results if you don't specify an embedded score option.

  3. Joins the matching results with the parent document if other query predicates are specified through the compound operator.

    Note

    For string faceting, Atlas Search counts string facets once for each document in the result set. For an example of this behavior, see Examples.

You can't highlight on queries inside the embeddedDocument operator.

The following examples use the sample_supplies.sales collection in the sample dataset. These examples use the following index definition on the collection:

{
"mappings": {
"dynamic": true,
"fields": {
"items": {
"dynamic": true,
"type": "embeddedDocuments"
},
"purchaseMethod": {
"type": "stringFacet"
}
}
}
}
←  compoundequals →
Share Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.