Navigation
This version of the documentation is archived and no longer supported.

Wildcard Index Restrictions

Incompatible Index Types or Properties

Wildcard indexes do not support the following index types or properties:

Note

Wildcard Indexes are distinct from and incompatible with Wildcard Text Indexes. Wildcard indexes cannot support queries using the $text operator.

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 on product_attributes. 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 on product_attributes. 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 on product_attributes. 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" ] ] }
}])
Field is not equal to 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 not equal to null.

For example, consider a collection inventory with a wildcard index on product_attributes. The wildcard index cannot support the following queries if product_attributes.tags is an array in any document in the collection:

db.inventory.find( { $ne : [ "product_attributes.tags", null ] } )

db.inventory.aggregate([{
  $match : { $ne : [ "product_attributes.tags", 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.