Wildcard Indexes通配符索引

On this page本页内容

MongoDB supports creating indexes on a field or set of fields to support queries. MongoDB支持在字段或字段集上创建索引以支持查询。Since MongoDB supports dynamic schemas, applications can query against fields whose names cannot be known in advance or are arbitrary.由于MongoDB支持动态模式,应用程序可以查询名称无法预先知道或任意的字段。

New in version MongoDB: 4.2在版本4.2中新增

MongoDB 4.2 introduces wildcard indexes for supporting queries against unknown or arbitrary fields.MongoDB 4.2引入了通配符索引,用于支持对未知或任意字段的查询。

Consider an application that captures user-defined data under the userMetadata field and supports querying against that data:考虑一个在userMetadata字段下捕获用户定义数据并支持对该数据进行查询的应用程序:

{ "userMetadata" : { "likes" : [ "dogs", "cats" ] } }
{ "userMetadata" : { "dislikes" : "pickles" } }
{ "userMetadata" : { "age" : 45 } }
{ "userMetadata" : "inactive" }

Administrators want to create indexes to support queries on any subfield of userMetadata.管理员希望创建索引以支持对userMetadata的任何子字段的查询。

A wildcard index on userMetadata can support single-field queries on userMetadata, userMetadata.likes, userMetadata.dislikes, and userMetadata.age:userMetadata上的通配符索引可以支持对userMetadatauserMetadata.likesuserMetadata.dislikesuserMetadata.age的单字段查询:

db.userData.createIndex( { "userMetadata.$**" : 1 } )

The index can support the following queries:索引可以支持以下查询:

db.userData.find({ "userMetadata.likes" : "dogs" })
db.userData.find({ "userMetadata.dislikes" : "pickles" })
db.userData.find({ "userMetadata.age" : { $gt : 30 } })
db.userData.find({ "userMetadata" : "inactive" })

A non-wildcard index on userMetadata can only support queries on values of userMetadata.userMetadata上的非通配符索引只能支持对userMetadata值的查询。

Important重要

Wildcard indexes are not designed to replace workload-based index planning. 通配符索引不是为了取代基于工作负载的索引规划而设计的。For more information on creating indexes to support queries, see Create Indexes to Support Your Queries. 有关创建索引以支持查询的更多信息,请参阅创建索引以支撑查询For complete documentation on wildcard index limitations, see Wildcard Index Restrictions.有关通配符索引限制的完整文档,请参阅通配符索引限制

Create Wildcard Index创建通配符索引

Important重要

The mongodfeatureCompatibilityVersion must be 4.2 to create wildcard indexes. mongod featureCompatibilityVersion必须为4.2才能创建通配符索引。For instructions on setting the fCV, see Set Feature Compatibility Version on MongoDB 5.0 Deployments.有关设置fCV的说明,请参阅在MongoDB 5.0部署上设置功能兼容性版本

You can create wildcard indexes using the createIndexes database command or its shell helpers, createIndex() or createIndexes().您可以使用createIndexes数据库命令或其shell助手createIndex()createIndexes()创建通配符索引。

Create a Wildcard Index on a Field在字段上创建通配符索引

To index the value of a specific field:要索引特定字段的值,请执行以下操作:

db.collection.createIndex( { "fieldA.$**" : 1 } )

With this wildcard index, MongoDB indexes all values of fieldA. 通过这个通配符索引,MongoDB对fieldA的所有值进行索引。If the field is a nested document or array, the wildcard index recurses into the document/array and stores the value for all fields in the document/array.如果字段是嵌套文档或数组,则通配符索引将递归到文档/数组中,并存储文档/数组内所有字段的值。

For example, documents in the product_catalog collection may contain a product_attributes field. 例如,product_catalog集合中的文档可能包含product_attributes字段。The product_attributes field can contain arbitrary nested fields, including embedded documents and arrays:product_attributes字段可以包含任意嵌套字段,包括嵌入式文档和数组:

{
  "product_name" : "Spy Coat",
  "product_attributes" : {
    "material" : [ "Tweed", "Wool", "Leather" ]
    "size" : {
      "length" : 72,
      "units" : "inches"
    }
  }
}
{
  "product_name" : "Spy Pen",
  "product_attributes" : {
     "colors" : [ "Blue", "Black" ],
     "secret_feature" : {
       "name" : "laser",
       "power" : "1000",
       "units" : "watts",
     }
  }
}

The following operation creates a wildcard index on the product_attributes field:以下操作在product_attributes字段上创建通配符索引:

db.products_catalog.createIndex( { "product_attributes.$**" : 1 } )

The wildcard index can support arbitrary single-field queries on product_attributes or its embedded fields:通配符索引可以支持对product_attributes或其嵌入字段的任意单字段查询:

db.products_catalog.find( { "product_attributes.size.length" : { $gt : 60 } } )
db.products_catalog.find( { "product_attributes.material" : "Leather" } )
db.products_catalog.find( { "product_attributes.secret_feature.name" : "laser" } )
Note注意

The path-specific wildcard index syntax is incompatible with the wildcardProjection option. 路径特定的通配符索引语法与wildcardProjection选项不兼容。See the Options for wildcard indexes for more information.有关更多信息,请参阅通配符索引选项

For an example, see Create a Wildcard Index on a Single Field Path.有关示例,请参阅在单个字段路径上创建通配符索引

Create a Wildcard Index on All Fields在所有字段上创建通配符索引

To index the value of all fields in a document (excluding _id), specify "$**" as the index key:要索引文档中所有字段的值(不包括_id),请指定"$**"作为索引键:

db.collection.createIndex( { "$**" : 1 } )

With this wildcard index, MongoDB indexes all fields for each document in the collection. 使用此通配符索引,MongoDB为集合中每个文档的所有字段编制索引。If a given field is a nested document or array, the wildcard index recurses into the document/array and stores the value for all fields in the document/array.如果给定字段是嵌套文档或数组,则通配符索引将递归到文档/数组中,并存储文档/数组内所有字段的值。

For an example, see Create a Wildcard Index on All Field Paths.有关示例,请参阅在所有字段路径上创建通配符索引

Note注意

Wildcard indexes omit the _id field by default. 默认情况下,通配符索引省略_id字段。To include the _id field in the wildcard index, you must explicitly include it in the wildcardProjection document. 要在通配符索引中包含_id字段,必须在wildcardProjection文档中显式包含它。See Options for wildcard indexes for more information.有关详细信息,请参阅通配符索引选项

Create a Wildcard Index on Multiple Specific Fields在多个特定字段上创建通配符索引

To index the values of multiple specific fields in a document:要索引文档中多个特定字段的值,请执行以下操作:

db.collection.createIndex(
  { "$**" : 1 },
  { "wildcardProjection" :
    { "fieldA" : 1, "fieldB.fieldC" : 1 }
  }
)

With this wildcard index, MongoDB indexes all values for the specified fields for each document in the collection. 使用此通配符索引,MongoDB为集合中每个文档的指定字段的所有值编制索引。If a given field is a nested document or array, the wildcard index recurses into the document/array and stores the value for all fields in the document/array.如果给定字段是嵌套文档或数组,则通配符索引将递归到文档/数组中,并存储文档/数组内所有字段的值。

Note注意

Wildcard indexes do not support mixing inclusion and exclusion statements in the wildcardProjection document except when explicitly including the _id field. 通配符索引不支持在wildcardProjection文档中混合包含语句和排除语句,除非显式包含_id字段。For more information on wildcardProjection, see the Options for wildcard indexes.有关wildcardProjection的更多信息,请参阅通配符索引选项

For an example, see Include Specific Fields in Wildcard Index Coverage.有关示例,请参阅在通配符索引覆盖率中包含特定字段

Create a Wildcard Index that Excludes Multiple Specific Fields创建排除多个特定字段的通配符索引

To index the fields of all fields in a document excluding specific field paths:要对文档中除特定字段路径之外的所有字段的字段进行索引,请执行以下操作:

db.collection.createIndex(
  { "$**" : 1 },
  { "wildcardProjection" :
    { "fieldA" : 0, "fieldB.fieldC" : 0 }
  }
)

With this wildcard index, MongoDB indexes all fields for each document in the collection excluding the specified field paths. 使用此通配符索引,MongoDB为集合中每个文档的所有字段编制索引,不包括指定的字段路径。If a given field is a nested document or array, the wildcard index recurses into the document/array and stores the values for all fields in the document/array.如果给定字段是嵌套文档或数组,则通配符索引将递归到文档/数组中,并存储文档/数组内所有字段的值。

For an example, see Omit Specific Fields from Wildcard Index Coverage.有关示例,请参阅从通配符索引覆盖率中省略特定字段

Note注意

Wildcard indexes do not support mixing inclusion and exclusion statements in the wildcardProjection document except when explicitly including the _id field. 通配符索引不支持在wildcardProjection文档中混合包含和排除语句,除非显式包含_id字段。For more information on wildcardProjection, see the Options for wildcard indexes.有关wildcardProjection的更多信息,请参阅通配符索引选项

Considerations注意事项

  • Wildcard indexes can support at most one field in any given query predicate. 通配符索引最多可以支持任何给定查询谓词中的一个字段。For more information on wildcard index query support, see Wildcard Index Query/Sort Support.有关通配符索引查询支持的更多信息,请参阅通配符索引查询/排序支持
  • The mongodfeatureCompatibilityVersion must be 4.2 to create wildcard indexes. mongodfeatureCompatibilityVersion必须为4.2才能创建通配符索引。For instructions on setting the fCV, see Set Feature Compatibility Version on MongoDB 5.0 Deployments.有关设置fCV的说明,请参阅在MongoDB 5.0部署上设置功能兼容性版本
  • Wildcard indexes omit the _id field by default. 默认情况下,通配符索引省略_ id字段。To include the _id field in the wildcard index, you must explicitly include it in the wildcardProjection document (i.e. { "_id" : 1 }).要在通配符索引中包含_id字段,必须在通配器投影文档中显式包含它(即{ "_id" : 1 })。
  • You can create multiple wildcard indexes in a collection.可以在集合中创建多个通配符索引。
  • A wildcard index may cover the same fields as other indexes in the collection.通配符索引可以覆盖与集合中其他索引相同的字段。
  • Wildcard indexes are Sparse Indexes and only contain entries for documents that have the indexed field, even if the index field contains a null value.通配符索引是稀疏索引,仅包含具有索引字段的文档的条目,即使索引字段包含空值。

Behavior行为

Wildcard indexes have specific behavior when indexing fields which are an object (i.e. an embedded document) or an array:当索引作为对象(即嵌入文档)或数组的字段时,通配符索引具有特定的行为:

  • If the field is an object, the wildcard index descends into the object and indexes its contents. 如果字段是对象,则通配符索引将下降到对象中并对其内容进行索引。The wildcard index continues descending into any additional embedded documents it encounters.通配符索引继续下降到它遇到的任何其他嵌入文档中。
  • If the field is an array, then the wildcard index traverses the array and indexes each element:如果字段是数组,则通配符索引遍历数组并为每个元素编制索引:

    • If an element in the array is an object, the wildcard index descends into the object to index its contents as described above.如果数组中的元素是对象,则通配符索引将下降到对象中,以对其内容进行索引,如上所述。
    • If the element is an array - that is, an array which is embedded directly within the parent array - then the wildcard index does not traverse the embedded array, but indexes the entire array as a single value.如果元素是数组-即直接嵌入父数组中的数组-则通配符索引不会遍历嵌入的数组,而是将整个数组作为单个值进行索引。
  • For all other fields, record the primitive (non-object/array) value into the index.对于所有其他字段,将基元(非对象/数组)值记录到索引中。

The wildcard index continues traversing any additional nested objects or arrays until it reaches a primitive value (i.e. a field that is not an object or array). 通配符索引继续遍历任何其他嵌套对象或数组,直到它达到原始值(即,不是对象或数组的字段)。It then indexes this primitive value, along with the full path to that field.然后,它对该原语值以及该字段的完整路径进行索引。

For example, consider the following document:例如,考虑以下文档:

{
  "parentField" : {
    "nestedField" : "nestedValue",
    "nestedObject" : {
      "deeplyNestedField" : "deeplyNestedValue"
    },
    "nestedArray" : [
      "nestedArrayElementOne",
      [ "nestedArrayElementTwo" ]
    ]
  }
}

A wildcard index which includes parentField records the following entries:包含parentField的通配符索引记录以下条目:

  • "parentField.nestedField" : "nestedValue"
  • "parentField.nestedObject.deeplyNestedField" : "deeplyNestedValue"
  • "parentField.nestedArray" : "nestedArrayElementOne"
  • "parentField.nestedArray" : ["nestedArrayElementTwo"]

Note that the records for parentField.nestedArray do not include the array position for each element. 请注意,parentField.nestedArray的记录不包括每个元素的数组位置。Wildcard indexes ignore array element positions when recording the element into the index. 在将元素记录到索引中时,通配符索引忽略数组元素位置。Wildcard indexes can still support queries that include explicit array indices. 通配符索引仍然可以支持包含显式数组索引的查询。See Queries with Explicit Array Indices for more information.有关详细信息,请参阅带有显式数组索引的查询。

For more information on wildcard index behavior with nested objects, see Nested Objects.有关嵌套对象的通配符索引行为的详细信息,请参阅嵌套对象

For more information on wildcard index behavior with nested arrays, see Nested Arrays.有关嵌套数组的通配符索引行为的详细信息,请参阅嵌套数组

Nested Objects嵌套对象

When a wildcard index encounters a nested object, it descends into the object and indexes its contents. 当通配符索引遇到嵌套对象时,它会下降到该对象中并为其内容编制索引。For example:例如:

{
  "parentField" : {
    "nestedField" : "nestedValue",
    "nestedArray" : ["nestedElement"]
    "nestedObject" : {
      "deeplyNestedField" : "deeplyNestedValue"
    }
  }
}

A wildcard index which includes parentField descends into the object to traverse and index its contents:包含parentField的通配符索引下降到对象中以遍历和索引其内容:

  • For each field which is itself an object (i.e. an embedded document), descend into the object to index its contents.对于本身是对象(即嵌入文档)的每个字段,向下进入对象以索引其内容。
  • For each field which is an array, traverse the array and index its contents.对于作为数组的每个字段,遍历数组并为其内容编制索引。
  • For all other fields, record the primitive (non-object/array) value into the index.对于所有其他字段,将基元(非对象/数组)值记录到索引中。

The wildcard index continues traversing any additional nested objects or arrays until it reaches a primitive value (i.e. a field that is not an object or array). 通配符索引继续遍历任何其他嵌套对象或数组,直到它达到原始值(即,不是对象或数组的字段)。It then indexes this primitive value, along with the full path to that field.然后,它对该原语值以及该字段的完整路径进行索引。

Given the sample document, the wildcard index adds the following records to the index:给定示例文档,通配符索引将以下记录添加到索引中:

  • "parentField.nestedField" : "nestedValue"
  • "parentField.nestedObject.deeplyNestedField" : "deeplyNestedValue"
  • "parentField.nestedArray" : "nestedElement"

For more information on wildcard index behavior with nested arrays, see Nested Arrays.有关嵌套数组的通配符索引行为的详细信息,请参阅嵌套数组

Nested Arrays嵌套数组

When a wildcard index encounters a nested array, it attempts to traverse the array to index its elements. 当通配符索引遇到嵌套数组时,它会尝试遍历数组以索引其元素。If the array is itself an element in a parent array (i.e. an embedded array), the wildcard index instead records the entire array as a value instead of traversing its contents. 如果数组本身是父数组(即嵌入数组)中的元素,则通配符索引将整个数组记录为值,而不是遍历其内容。For example:例如:

{
  "parentArray" : [
    "arrayElementOne",
    [ "embeddedArrayElement" ],
    "nestedObject" : {
      "nestedArray" : [
        "nestedArrayElementOne",
        "nestedArrayElementTwo"
      ]
    }
  ]
}

A wildcard index which includes parentArray descends into the array to traverse and index its contents:包含parentArray的通配符索引下降到数组中以遍历和索引其内容:

  • For each element which is an array (i.e. an embedded array), index the entire array as a value.对于作为数组(即嵌入式数组)的每个元素,将整个数组作为值进行索引。
  • For each element which is an object, descend into the object to traverse and index its contents.对于作为对象的每个元素,向下进入对象以遍历和索引其内容。
  • For all other fields, record the primitive (non-object/array) value into the index.对于所有其他字段,将基元(非对象/数组)值记录到索引中。

The wildcard index continues traversing any additional nested objects or arrays until it reaches a primitive value (i.e. a field that is not an object or array). 通配符索引继续遍历任何其他嵌套对象或数组,直到它达到原始值(即,不是对象或数组的字段)。It then indexes this primitive value, along with the full path to that field.然后,它对该原语值以及该字段的完整路径进行索引。

Given the sample document, the wildcard index adds the following records to the index:给定示例文档,通配符索引将以下记录添加到索引中:

  • "parentArray" : "arrayElementOne"
  • "parentArray" : ["embeddedArrayElement"]
  • "parentArray.nestedObject.nestedArray" : "nestedArrayElementOne"
  • "parentArray.nestedObject.nestedArray" : "nestedArrayElementTwo"

Note that the records for parentField.nestedArray do not include the array position for each element. 请注意,parentField.nestedArray的记录不包括每个元素的数组位置。Wildcard indexes ignore array element positions when recording the element into the index. 在将元素记录到索引中时,通配符索引忽略数组元素位置。Wildcard indexes can still support queries that include explicit array indices. 通配符索引仍然可以支持包含显式数组索引的查询。See Queries with Explicit Array Indices for more information.有关详细信息,请参阅带有显式数组索引的查询

Restrictions限制

  • You cannot shard a collection using a wildcard index. 不能使用通配符索引分割集合。Create a non-wildcard index on the field or fields you want to shard on. 在要分片的一个或多个字段上创建非通配符索引。For more information on shard key selection, see Shard Keys.有关分片关键点选择的详细信息,请参阅分片键
  • You cannot create a compound index.不能创建复合索引。
  • You cannot specify the following properties for a wildcard index:不能为通配符索引指定以下属性:

  • You cannot create the following index types using wildcard syntax:不能使用通配符语法创建以下索引类型:

Important重要

Wildcard Indexes are distinct from and incompatible with Wildcard Text Indexes. 通配符索引与通配符文本索引不同,并且不兼容。Wildcard indexes cannot support queries using the $text operator.通配符索引不能支持使用$text运算符的查询。

For complete documentation on wildcard index creation restrictions, see Incompatible Index Types or Properties.有关通配符索引创建限制的完整文档,请参阅不兼容索引类型或属性

Wildcard Index Query/Sort Support通配符索引查询/排序支持

Covered Queries复盖查询

Wildcard indexes can support a covered queryonly if all of the following are true:如果满足以下所有条件,则通配符索引可以支持覆盖查询

  • The query planner selects the wildcard index for satisfying the query predicate.查询规划器选择通配符索引以满足查询谓词。
  • The query predicate specifies exactly one field covered by the wildcard index.查询谓词只指定通配符索引覆盖的一个字段。
  • The projection explicitly excludes _id and includes only the query field.投影显式排除_id并仅包括查询字段。
  • The specified query field is never an array.指定的查询字段永远不是数组。

Consider the following wildcard index on the employees collection:考虑employees集合上的以下通配符索引:

db.employees.createIndex( { "$**" : 1 } )

The following operation queries for a single field lastName and projects out all other fields from the resulting document:以下操作查询单个字段lastName,并从结果文档中投影出所有其他字段:

db.employees.find(
  { "lastName" : "Doe" },
  { "_id" : 0, "lastName" : 1 }
)

Assuming that the specified lastName is never an array, MongoDB can use the $** wildcard index for supporting a covered query.假设指定的lastName永远不是数组,MongoDB可以使用$**通配符索引来支持覆盖查询。

Multi-Field Query Predicates多字段查询谓词

Wildcard indexes can support at most one query predicate field. 通配符索引最多可以支持一个查询谓词字段。That is:即:

  • MongoDB cannot use a non-wildcard index to satisfy one part of a query predicate and a wildcard index to satisfy another.MongoDB不能使用非通配符索引来满足查询谓词的一部分,而使用通配符指数来满足另一部分。
  • MongoDB cannot use one wildcard index to satisfy one part of a query predicate and another wildcard index to satisfy another.MongoDB不能使用一个通配符索引来满足查询谓词的一部分,而使用另一个通配索引来满足另一部分。
  • Even if a single wildcard index could support multiple query fields, MongoDB can use the wildcard index to support only one of the query fields. 即使单个通配符索引可以支持多个查询字段,MongoDB也可以使用通配符指数只支持其中一个查询字段。All remaining fields are resolved without an index.所有剩余字段在没有索引的情况下解析。

However, MongoDB may use the same wildcard index for satisfying each independent argument of the query $or or aggregation $or operators.但是,MongoDB可以使用相同的通配符索引来满足查询$or或聚合$or运算符的每个独立参数。

Queries with Sort带排序的查询

MongoDB can use a wildcard index for satisfying the sort() only if all of the following are true:MongoDB可以使用通配符索引来满足sort(),前提是以下所有条件均为真:

  • The query planner selects the wildcard index for satisfying the query predicate.查询规划器选择通配符索引以满足查询谓词。
  • The sort() specifies only the query predicate field.sort()仅指定查询谓词字段。
  • The specified field is never an array.指定的字段永远不是数组。

If the above conditions are not met, MongoDB cannot use the wildcard index for the sort. 如果不满足上述条件,MongoDB将无法使用通配符索引进行排序。MongoDB does not support sort() operations that require a different index from that of the query predicate. MongoDB不支持需要不同于查询谓词索引的sort()操作。For more information, see Index Intersection and Sort.有关详细信息,请参阅索引交集和排序

Consider the following wildcard index on the products collection:考虑products集合上的以下通配符索引:

db.products.createIndex( { "product_attributes.$**" : 1 } )

The following operation queries for a single field product_attributes.price and sorts on that same field:以下操作查询单个字段product_attribute.price,并对该字段进行排序:

db.products.find(
  { "product_attributes.price" : { $gt : 10.00 } },
).sort(
  { "product_attributes.price" : 1 }
)

Assuming that the specified price is never an array, MongoDB can use the product_attributes.$** wildcard index for satisfying both the find() and sort().假设指定的价格永远不是数组,MongoDB可以使用product_attributes.$**满足find()sort()的通配符索引。

Unsupported Query Patterns不支持的查询模式

  • Wildcard indexes cannot support query condition that checks if a field does not exist.通配符索引不支持检查字段是否不存在的查询条件。
  • Wildcard indexes cannot support query condition that checks if a field is or is not equal to a document or an array通配符索引不支持检查字段是否等于文档或数组的查询条件
  • Wildcard indexes cannot support query condition that checks if a field is not equal to null.通配符索引不支持检查字段是否不等于null的查询条件。

For details, see Unsupported Query and Aggregation Patterns.有关详细信息,请参阅不支持的查询和聚合模式

Queries with Explicit Array Indices具有显式数组索引的查询

MongoDB wildcard indexes do not record the array position of any given element in an array during indexing. MongoDB通配符索引在索引期间不记录数组中任何给定元素的数组位置。However, MongoDB may still select the wildcard index to answer a query which includes a field path with one or more explicit array indices (for example, parentArray.0.nestedArray.0). 但是,MongoDB仍然可以选择通配符索引来回答包含具有一个或多个显式数组索引的字段路径的查询(例如,parentArray.0.nestedArray.0)。Due to the increasing complexity of defining index bounds for each consecutive nested array, MongoDB does not consider the wildcard index to answer a given field path in the query if that path contains more than 8 explicit array indices. 由于为每个连续嵌套数组定义索引边界越来越复杂,如果路径包含8个以上的显式数组索引,MongoDB不会考虑使用通配符索引来回答查询中的给定字段路径。MongoDB can still consider the wildcard index to answer other field paths in the query.MongoDB仍然可以考虑使用通配符索引来回答查询中的其他字段路径。

For Example:例如

{
  "parentObject" : {
    "nestedArray" : [
       "elementOne",
       {
         "deeplyNestedArray" : [ "elementTwo" ]
       }
     ]
  }
}

MongoDB can select a wildcard index which includes parentObject to satisfy the following queries:MongoDB可以选择包含parentObject的通配符索引,以满足以下查询:

  • "parentObject.nestedArray.0" : "elementOne"
  • "parentObject.nestedArray.1.deeplyNestedArray.0" : "elementTwo"

If a given field path in the query predicate specifies more than 8 explicit array indices, MongoDB does not consider the wildcard index for answering that field path. 如果查询谓词中的给定字段路径指定了8个以上的显式数组索引,MongoDB将不考虑用于回答该字段路径的通配符索引。MongoDB instead either selects another eligible index to answer the query, or performs a collection scan.相反,MongoDB要么选择另一个符合条件的索引来回答查询,要么执行集合扫描。

Note that wildcard indexes themselves do not have any limits on the depth to which they traverse a document while indexing it; the limitation only applies to queries which explicitly specify exact array indices. 请注意,通配符索引本身对索引文档时遍历文档的深度没有任何限制;该限制仅适用于显式指定精确数组索引的查询。By issuing the same queries without the explicit array indices, MongoDB may select the wildcard index to answer the query:通过发出没有显式数组索引的相同查询,MongoDB可以选择通配符索引来回答查询:

  • "parentObject.nestedArray" : "elementOne"
  • "parentObject.nestedArray.deeplyNestedArray" : "elementTwo"
←  Limit the Number of Entries ScannedWildcard Index Restrictions →