[DOCS-16016] [Server] Incorrect documentation section on unsupported query operations in wildcard indexes Created: 06/Apr/23  Updated: 30/Oct/23  Resolved: 11/Apr/23

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Critical - P2
Reporter: Alexander Ignatyev Assignee: Jeffrey Allen
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-75544 Wildcard Index not working as expecte... Closed
Participants:
Days since reply: 43 weeks, 5 days ago

 Description   

Wildcard Indexes are always sparse indexes by default, therefore, as other sparse indexes they cannot answer queries in case of incomplete results ({$exists: true}, {$eq: null}). However, they can answer queries with {$ne: null}: SERVER-36465
Unfortunately, our documentation on Wildcard Indexes is not fully correct in that respect, it states that Wildcard Indexes cannot answer {$ne: null}, instead of {$eq: null}.
To address the issue we need to fix fix the documentation in a few places:

1. https://www.mongodb.com/docs/manual/core/index-wildcard/#unsupported-query-patterns.

Statement "Wildcard indexes cannot support query condition that checks if a field is not equal to null." should be replaced to "Wildcard indexes cannot support query condition that checks if a field is equal to null."


2. https://www.mongodb.com/docs/v5.0/reference/index-wildcard-restrictions/#unsupported-query-and-aggregation-patterns

Section "Field is not equal to null" should be renamed to something like "Array Field equality to null".

And the section's text "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:"

should be rewritten to something like

"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.

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:"

The examples to the section contain incorrect MQL and should be replaced to 

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

A new section should be added:

Field is equal to null

Wildcard indexes cannot support queries for documents where a field is equal to null. This is because the semantics of {$eq: null} is such that it must match all documents where the field is explicitly null or missing, and wildcard indexes, being sparse, do not index the latter documents.

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": {$eq: null } } )
 
db.inventory.aggregate([{
  $match : {"product_attributes.price": {$eq: null}}
}])

One workaround is to to use {$type: 10} instead:

db.inventory.find( {"product_attributes.price": {$type: 10 } } )
 
db.inventory.aggregate([{
  $match : {"product_attributes.price": {$type: 10}}
}])


3. https://www.mongodb.com/docs/manual/core/index-sparse/#indexes-that-are-sparse-by-default

Statement "2dsphere (version 2), 2d, geoHaystack, and text indexes are always sparse." should rewritten with a link to wildcard indexes added, e.g.:
"2dsphere (version 2), 2d, geoHaystack, text, and wildcard indexes are always sparse."

Not required but good to have for completeness.



 Comments   
Comment by Jeffrey Allen [ 07/Apr/23 ]

Hi alexander.ignatyev@mongodb.com , could you please review this PR?

https://github.com/10gen/docs-mongodb-internal/pull/2899

Thanks!

Comment by Jeffrey Allen [ 07/Apr/23 ]

PR: https://github.com/10gen/docs-mongodb-internal/pull/2899

Comment by Sarah Olson [ 07/Apr/23 ]

We'll be working on this. It duplicates https://jira.mongodb.org/browse/DOCS-16010, which we closed as this ticket has more detail. 

Generated at Thu Feb 08 08:14:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.