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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 3.5.7
    • None
    • Server
    • 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

        Activity

          People

            pavithra.vetriselvan@mongodb.com Pavithra Vetriselvan
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              6 years, 22 weeks, 6 days ago