Wildcard Index Restrictions通配符索引限制
On this page
Incompatible Index Types or Properties不兼容的索引类型或属性
Wildcard indexes do not support the following index types or properties:通配符索引不支持以下索引类型或属性:
Wildcard Indexes are distinct from and incompatible with Wildcard Text Indexes. Wildcard indexes cannot support queries using the 通配符索引不同于通配符文本索引,并且与通配符文本索引不兼容。通配符索引不能支持使用$text
operator.$text
运算符的查询。
Unsupported Query and Aggregation Patterns不支持的查询和聚合模式
Field does not exist字段不存在-
Wildcard indexes are sparse and do not index empty fields.通配符索引是稀疏的,不对空字段进行索引。Wildcard indexes therefore cannot support querying for documents where a field does not exist.因此,通配符索引无法支持查询不存在字段的文档。For example, consider a collection例如,考虑在inventory
with a wildcard index onproduct_attributes
.product_attributes
上具有通配符索引的集合inventory
。The wildcard index cannot support the following queries:通配符索引无法支持以下查询:db.inventory.find( {"product_attributes" : { $exists : false } } )
db.inventory.aggregate([
{ $match : { "product_attributes" : { $exists : false } } }
]) Field is equal to a document or an array字段等于文档或数组-
Wildcard indexes generate entries for the contents of a document or array, and not the document/array itself.通配符索引为文档或数组的内容生成条目,而不是文档/数组本身。Wildcard indexes therefore cannot support exact document/array equality matches.因此,通配符索引无法支持精确的文档/数组相等匹配。Wildcard indexes can support querying where the field equals an empty document通配符索引可以支持查询字段等于空文档{}
.{}
的位置。For example, consider a collection例如,考虑在inventory
with a wildcard index onproduct_attributes
.product_attributes
上具有通配符索引的集合inventory
。The wildcard index cannot support the following queries:通配符索引无法支持以下查询:db.inventory.find({ "product_attributes" : { "price" : 29.99 } } )
db.inventory.find({ "product_attributes.tags" : [ "waterproof", "fireproof" ] } )
db.inventory.aggregate([{
$match : { "product_attributes" : { "price" : 29.99 } }
}])
db.inventory.aggregate([{
$match : { "product_attributes.tags" : ["waterproof", "fireproof" ] } }
}]) Field is not equal to a document or array字段不等于文档或数组-
Wildcard indexes generate entries for the contents of a document or array, and not the document/array itself.通配符索引为文档或数组的内容生成条目,而不是文档/数组本身。Wildcard indexes therefore cannot support exact document/array inequality matches.因此,通配符索引无法支持精确的文档/数组不等式匹配。For example, consider a collection例如,考虑在inventory
with a wildcard index onproduct_attributes
.product_attributes
上具有通配符索引的集合inventory
。The wildcard index cannot support the following queries:通配符索引无法支持以下查询:db.inventory.find( { $ne : [ "product_attributes", { "price" : 29.99 } ] } )
db.inventory.find( { $ne : [ "product_attributes.tags", [ "waterproof", "fireproof" ] ] } )
db.inventory.aggregate([{
$match : { $ne : [ "product_attributes", { "price" : 29.99 } ] }
}])
db.inventory.aggregate([{
$match : { $ne : [ "product_attributes.tags", [ "waterproof", "fireproof" ] ] }
}]) Array Field is equal or not equal to null数组字段等于或不等于null
-
If a given field is an array in any document in the collection, wildcard indexes cannot support queries for documents where that field is equal or not equal to null.如果给定字段是集合中任何文档中的数组,则通配符索引无法支持查询该字段等于或不等于null
的文档。For example, consider a collection例如,考虑在inventory
with a wildcard index onproduct_attributes
.product_attributes
上具有通配符索引的集合inventory
。The wildcard index cannot support the following queries if如果product_attributes.tags
is an array in any document in the collection:product_attributes.tags
是集合中任何文档中的数组,则通配符索引无法支持以下查询:db.inventory.find( { "product_attributes.tags": { $ne: null } } )
db.inventory.find( { "product_attributes.tags": null } )
db.inventory.aggregate([{
$match : { "product_attributes.tags": { $ne: null } }
}])
db.inventory.aggregate([{
$match : { "product_attributes.tags": null }
}]) Field is equal to null字段等于null
-
Wildcard indexes cannot support queries for documents where a field is equal to null.通配符索引不能支持对字段等于null
的文档进行查询。The query查询{ $eq: null }
matches all documents where the field is null or missing.{ $eq: null }
匹配字段为null
或缺失的所有文档。Wildcard are sparse, meaning they do not index the documents where the indexed field is missing, and therefore cannot support a match on null.通配符是稀疏的,这意味着它们不会对缺少索引字段的文档进行索引,因此无法支持null
匹配。For example, consider a collection例如,考虑在inventory
with a wildcard index onproduct_attributes
.product_attributes
上具有通配符索引的集合inventory
。The wildcard index cannot support the following queries:通配符索引无法支持以下查询:db.inventory.find( { "product_attributes.price": { $eq: null } } )
db.inventory.aggregate([{
$match : { "product_attributes.price": { $eq: null } }
}])
Sharding分片
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.有关分片关键帧选择的详细信息,请参阅分片关键帧。