[DOCS-10226] New behavior for {field: {$type: "array"}} Created: 08/May/17  Updated: 29/Oct/23  Resolved: 18/Sep/17

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: 3.5.7

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: Pavithra Vetriselvan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-1475 {field: {$type:"array"}} should retur... Closed
Participants:
Days since reply: 6 years, 22 weeks, 6 days ago
Epic Link: DOCS: 3.6 Server

 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.



 Comments   
Comment by Githook User [ 07/Sep/17 ]

Author:

{'name': 'Pavithra Vetriselvan', 'email': 'pavi@MacBook-Pro-77.local'}

Message: DOCS-10226 added documentation for type: array behavior in compatibility release notes and 3.6 docs
Branch: master
https://github.com/mongodb/docs/commit/3de3a738b58a28935a0c0e938bca824d375c6169

Comment by Githook User [ 07/Sep/17 ]

Author:

{'name': 'Pavithra Vetriselvan', 'email': 'pavi@MacBook-Pro-77.local'}

Message: DOCS-10226 updated the behavior of type array expression in release notes and 3.6 documentation
Branch: master
https://github.com/mongodb/docs/commit/83e94b688ebd03437ce544bcbfedc746a93a2957

Comment by David Storch [ 12/May/17 ]

One more very important point: this change will affect users on 3.4.x who have partial indexes whose partialFilterExpression has a $type:"array" expression and wish to upgrade to 3.6. As part of the upgrade process, such users must rebuild any such partial index when first starting a 3.6 node. Failing to do so could cause the user to experience a mix of the old and new $type:"array" semantics. We should clearly document this wrinkle in the 3.6 compatibility notes so that users who may be affected can take the appropriate action.

Note that everything said in this ticket also applies to $type:4, since 4 is the type code for BSON arrays.

Comment by Ravind Kumar (Inactive) [ 08/May/17 ]

steve.renaker

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