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

New behavior for {field: {$type: "array"}}

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.5.7
    • Component/s: Server
    • Labels:
      None

      Description

      In SERVER-1475, fixed in 3.5.7 and planned to be made generally available in the 3.6.0 release, we made a minor breaking change to the behavior of the $type query operator. The operator's existing reference page is here:

      https://docs.mongodb.com/manual/reference/operator/query/type/

      Specifically, we changed the behavior of $type:"array". Previously, such a query would only match documents with nested arrays:

      > db.c.find()
      { "_id" : ObjectId("59108bb673650abe22f32a56"), "a" : [ 1, 2, 3 ] }
      { "_id" : ObjectId("59108bbc73650abe22f32a57"), "a" : [ 1, [ 2, 3 ] ] }
      > db.c.find({a: {$type: "array"}})
      { "_id" : ObjectId("59108bbc73650abe22f32a57"), "a" : [ 1, [ 2, 3 ] ] }
      

      The new behavior, which we believe to be more intuitive and more consistent with existing query semantics, is to match both nested arrays and non-nested arrays:

      > db.c.find({a: {$type: "array"}})
      { "_id" : ObjectId("59108bb673650abe22f32a56"), "a" : [ 1, 2, 3 ] }
      { "_id" : ObjectId("59108bbc73650abe22f32a57"), "a" : [ 1, [ 2, 3 ] ] }
      

      This change needs to be documented as part of the Compatibility Changes page in the 3.6 release notes. We also need to update the Querying by Array Type section for the 3.6 references pages, since this currently is dedicated to describing the old behavior.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              pavithra.vetriselvan Pavithra Vetriselvan
              Reporter:
              david.storch David Storch
              Participants:
              Last commenter:
              Ian Whalen Ian Whalen
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since reply:
                4 years, 3 weeks, 2 days ago
                Date of 1st Reply: