[SERVER-11455] {$type: Object} operator does not work with dot notation on array elements Created: 29/Oct/13  Updated: 11/Jul/16  Resolved: 21/Nov/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.4.5
Fix Version/s: 2.5.5

Type: Bug Priority: Major - P3
Reporter: Alvin Richards (Inactive) Assignee: Benety Goh
Resolution: Done Votes: 0
Labels: 26qa, nqf, query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

> db.serverBuildInfo()
{
"version" : "2.5.4-pre-",
"gitVersion" : "d8ca8b5faa1447365403cfb8da16a041e7d31d95",
"OpenSSLVersion" : "",
"sysInfo" : "Darwin vero 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49",
"loaderFlags" : "-fPIC -pthread -Wl,-bind_at_load -mmacosx-version-min=10.6",
"compilerFlags" : "-Wnon-virtual-dtor -Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wno-unknown-pragmas -Winvalid-pch -pipe -O3 -Wno-unused-function -Wno-deprecated-declarations -mmacosx-version-min=10.6",
"allocator" : "tcmalloc",
"versionArray" : [
2,
5,
4,
-100
],
"javascriptEngine" : "V8",
"bits" : 64,
"debug" : false,
"maxBsonObjectSize" : 16777216,
"ok" : 1
}


Attachments: File server11455.js    
Issue Links:
Related
Operating System: ALL
Participants:

 Description   

Queries for BSON type Object on array elements specified using the dot notation and the $type operator do not match valid documents in a collection.

Example query:

{a: {'b.0': {$type: 3}}} // 3 is BSON type for Object - does not match documents
{a: {'b.0': {$type: 2}}} // 2 is BSON type for String - works fine

http://docs.mongodb.org/manual/core/document/#document-dot-notation

http://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type

----------------
Problem:
2.4 executes equality matches differently depending on the structure of the document.

NOTE This appears to be fixed in 2.5.4-Pre

Reproduce:

db.q.drop()
db.q.insert({ "b" : [ 314159265011, { "a" : "" } ] })
db.q.insert({ "b" : [ true, { "b" : "I took a speed reading course and read \"War and Peace\" in twenty minutes. It involves Russia." } ] })
db.q.insert({ "b" : [ {}, { "b" : Date(1380451200000) } ] })
db.q.insert({ "b" : [ 314159265004, { "d" : { "d" : 0, "c" : 314159265012 } } ] })
db.q.insert({ "b" : [ 314159265005, { "d" : { "d" : "We are what we repeatedly do; excellence, then, is not an act but a habit." } }, "My pessimism extends to the point of even suspecting the sincerity of the pessimists.", "" ] })
db.q.insert({ "b" : [ 1, { "a" : {} } ] })
db.q.insert({ "b" : [ "", { "2" : { "d" : { "d" : {} } } } ] })
db.q.insert({ "b" : [ "You must be the change you wish to see in the world.", { "a" : true }, false ], "a" : 1 })
db.q.insert({ "b" : [ false, { "c" : "" } ] })
db.q.insert({ "b" : [ 314159265009, {"d" : Date(1380412800000) }, 314159265000 ] })
db.q.insert({ "b" : [ Date(0), { "b" : 0 } ] })
db.q.insert({ "b" : [ Date(1380451200000), { "d" : 0 } ] })
db.q.insert({ "b" : [ 4.940656458412465e-324, { "a" : "To the man who only has a hammer, everything he encounters begins to look like a nail." } ], "c" : Date(1380451200000) })
db.q.insert({ "b" : [ { "b" : "" }, { "0" : { "c" : "Asking a working writer what he thinks about critics is like asking a lamppost how it feels about dogs." } } ] })
db.q.insert({ "b" : [ "", { "a" : 4.940656458412465e-324 } ] })
db.q.insert({ "b" : [ Date(0), {} ] })
db.q.insert({ "b" : [ {}, { "c" : Infinity } ] })
db.q.insert({ "b" : [ 1, { "c" : [ {} ] } ] })

Query 1

db.q.find( { "b.1" : { $type : 3 } } ).count()

2.4.5: 18 docs returned
2.5.4-Pre: Zero docs returned

Query 2

db.q.find( { "x" : { $type : 3 } } ).count()

2.4.5: Zero docs returned
2.5.4-Pre: Zero docs returned



 Comments   
Comment by Thomas Zahn [ 01/Mar/14 ]

Unfortunately, the $type operator still does not seem to work properly with nested (i.e. multi-level) array elements in combination with the dot notation.
I created a separate bug report for this:
SERVER-12754

Comment by Githook User [ 21/Nov/13 ]

Author:

{u'username': u'benety', u'name': u'Benety Goh', u'email': u'benety@mongodb.com'}

Message: SERVER-11455 added Object to support types for dollar type operator when working with arrays
Branch: master
https://github.com/mongodb/mongo/commit/8be0b2c53e00f769ef480bbc882ae6828c6795b3

Comment by Benety Goh [ 12/Nov/13 ]

breaks down test by testing positional and $type components separately

Generated at Thu Feb 08 03:25:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.