Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-16016

[Server] Incorrect documentation section on unsupported query operations in wildcard indexes

      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:

      Unable to find source-code formatter for language: javescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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:

      Unable to find source-code formatter for language: javescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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.

            Assignee:
            jeffrey.allen@mongodb.com Jeffrey Allen
            Reporter:
            alexander.ignatyev@mongodb.com Alexander Ignatyev
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:
              1 year, 3 weeks ago