[SERVER-20706] Comparison operators do not work embedded documents Created: 30/Sep/15  Updated: 30/Sep/15  Resolved: 30/Sep/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.1.5
Fix Version/s: None

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

Issue Links:
Duplicate
duplicates SERVER-18959 Cannot use comparaison operator to qu... Closed
Operating System: ALL
Steps To Reproduce:

> db.t2.insert({"bef" : { "dt" : 20090401 }})
WriteResult({ "nInserted" : 1 })
> db.t2.find({"bef" : { "dt" : 20090401 }})
{ "_id" : ObjectId("560c32d8bb3c86325d09eead"), "bef" : { "dt" : 20090401 } }
> db.t2.find({"bef" : { "dt" : {$lte: 20090401} }})
> db.t2.find({"bef.dt" : {$lte: 20090401} })
{ "_id" : ObjectId("560c32d8bb3c86325d09eead"), "bef" : { "dt" : 20090401 } }

Participants:

 Description   

If you want to query embedded document, for example, "dt" of {"bef" : { "dt" : 20090401 }} and compare it with a value, simple comparison ({ "dt" : 20090401 }) will work, but $lte/$gte and other comparison operators would not



 Comments   
Comment by David Storch [ 30/Sep/15 ]

kay.kim, do we currently have any query language documentation that could help users with the "gotcha" reported here and in SERVER-18959? If not, it would be worth adding.

Comment by Sveta [ 30/Sep/15 ]

David,

Thank you for the explanation. Wouldn't it be good idea to update documentation at http://docs.mongodb.org/manual/reference/operator/query-comparison/ with similar explanation?

Comment by David Storch [ 30/Sep/15 ]

Hi svetasmirnova,

I am closing this ticket as a duplicate of SERVER-18959, which has been closed as Works as Designed. The query

db.t2.find({"bef" : { "dt" : {$lte: 20090401} }})

means to find documents where the "bef" field contains the literal nested object { "dt" : {$lte: 20090401} }. It does not mean to find documents where there is a path "def.dt" containing a numerical value less than or equal to 20090401. Note that { "dt" : {$lte: 20090401} } is not actually a valid user document for storage in a collection due to the dollar-prefixed "$lte" field. However, the query engine does not currently validate that a query for a literal nested document contains a valid document for storage since this would be wasted work for most queries.

Best,
Dave

Comment by Sveta [ 30/Sep/15 ]

Originally reported at https://groups.google.com/forum/#!topic/tokumx-user/FXVdkhRa80Y

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