[SERVER-8904] The data type of a value is causing error: { "$err" : "requested keyPattern does not match specified keys", "code" : 10365 } Created: 07/Mar/13  Updated: 19/Mar/13  Resolved: 11/Mar/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.0.2, 2.2.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Carl Youngblood Assignee: Aaron Staple
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

Please see description

Participants:

 Description   

> db.challenge_157_daily_scores.find().hint(
...

{ ... g:1, ... d:-1, ... s:-1, ... i:1, ... t:1 ... }

).sort(
...

{ ... g:1, ... d:-1, ... s:-1, ... i:1, ... t:1 ... }

)._addSpecial('$returnKey',true).min(
...

{ ... g: 1, ... d: ISODate("2013-03-07T00:00:00Z"), ... s: 2000, ... i: 1, ... t: 'u' ... }

).max(
... {
... "g" : 1,
... "d" : 1,
... "s" :

{ ... "$minElement" : 1 ... }

,
... "i" :

{ ... "$maxElement" : 1 ... }

,
... "t" :

{ ... "$maxElement" : 1 ... }

... }
... );

{ "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 1719, "i" : 24579031, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 1472, "i" : 24579049, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 1298, "i" : 24579022, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 1228, "i" : 24579013, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 1159, "i" : 24579033, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 814, "i" : 24579045, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 747, "i" : 24579014, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 487, "i" : 24579032, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 412, "i" : 24579038, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-07T00:00:00Z"), "s" : 164, "i" : 24579019, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-06T00:00:00Z"), "s" : 1555, "i" : 24579047, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-06T00:00:00Z"), "s" : 1317, "i" : 24579029, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-05T00:00:00Z"), "s" : 1998, "i" : 24579013, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-05T00:00:00Z"), "s" : 1882, "i" : 24579008, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-05T00:00:00Z"), "s" : 1654, "i" : 24579032, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-05T00:00:00Z"), "s" : 1533, "i" : 24579036, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-05T00:00:00Z"), "s" : 1333, "i" : 24579052, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-05T00:00:00Z"), "s" : 1219, "i" : 24579019, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-05T00:00:00Z"), "s" : 1047, "i" : 24579015, "t" : "u" } { "g" : 1, "d" : ISODate("2013-03-05T00:00:00Z"), "s" : 782, "i" : 24579043, "t" : "u" }

Looks good!

> db.challenge_157_daily_scores.find().hint(
...

{ ... g:1, ... d:-1, ... s:-1, ... i:1, ... t:1 ... }

).sort(
...

{ ... g:1, ... d:-1, ... s:-1, ... i:1, ... t:1 ... }

)._addSpecial('$returnKey',true).min(
...

{ ... g: 1, ... d: ISODate("2013-03-07T00:00:00Z"), ... s: 2000, ... i: 1, ... t: 'u' ... }

).max(
... {
... "g" : 1,
... "d" : ISODate("2013-03-07T00:00:00Z"),
... "s" :

{ ... "$minElement" : 1 ... }

,
... "i" :

{ ... "$maxElement" : 1 ... }

,
... "t" :

{ ... "$maxElement" : 1 ... }

... }
... );
error: {
"$err" : "requested keyPattern does not match specified keys",
"code" : 10365
}

Changing d from an integer (1) to an ISODate shouldn't affect the keyPattern.



 Comments   
Comment by Carl Youngblood [ 11/Mar/13 ]

Thank you!

Comment by Aaron Staple [ 11/Mar/13 ]

Hi Carl - I'm going to close this as "works as designed" but feel free to reopen if you have further questions.

Comment by Aaron Staple [ 11/Mar/13 ]

Hi Carl,

The main thing to keep in mind here is that you cannot specify a max bound that compares less than your min bound. Here are your min and max bounds in the different examples:

1:
min

{g:1,d:ISODate('2013-01-01'),s:700,i:0,t:0}

max {g:1,d:ISODate('2013-01-01'),s:{},i:1,t:1}

In this case, 'g' and 'd' are equal. The 's' field is an object in max and a number in min. Objects generally compare greater than numbers, however in this case you have specified descending comparison on the 's' field so {} will be considered less than 700 and the min / max values are not allowed.

2:
min

{g:1,d:ISODate('2013-01-01'),s:700,i:0,t:0}

max {g:1,d:ISODate('2013-01-01'),s:1,i:{},t:1}

In this case, 700 > 1 so compares "less" because of the descending order on the 's' field.

3:
min

{g:1,d:ISODate('2013-01-01'),s:700,i:0,t:0}

max {g:1,d:1,s:{},i:1,t:1}

Because there is an equality on 'g', ordering is based on the 'd' field. Generally a date compares greater than a number, but since you have a descending order on the 'd' field min will be less than max so your min and max are allowed.

Comment by Carl Youngblood [ 09/Mar/13 ]

My bad! Thank you for correcting my Min/MaxKey syntax. However, it does mean that my previous use of

{'$minKey':1}

was just a plain object, so there still seems to be inconsistent behavior.

 
// Query 1
 
> db.test.find().hint({g:1,d:-1,s:-1,i:1,t:1}).min({g:1,d:ISODate('2013-01-01'),s:700,i:0,t:0}).max({g:1,d:ISODate('2013-01-01'),s:{},i:1,t:1})
error: {
        "$err" : "requested keyPattern does not match specified keys",
        "code" : 10365
}
 
// Query 2
//   Just moving the dictionary from the s key to the i key stops causing error 10365
 
> db.test.find().hint({g:1,d:-1,s:-1,i:1,t:1}).min({g:1,d:ISODate('2013-01-01'),s:700,i:0,t:0}).max({g:1,d:ISODate('2013-01-01'),s:1,i:{},t:1})
{ "_id" : ObjectId("5139406d0518ed58a08d64c0"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 700, "i" : 0, "t" : 0 }
{ "_id" : ObjectId("513940700518ed58a08d64c1"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 600, "i" : 0, "t" : 0 }
{ "_id" : ObjectId("513940740518ed58a08d64c2"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 500, "i" : 0, "t" : 0 }
{ "_id" : ObjectId("513941f60518ed58a08d64c9"), "g" : [ 1, 2 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 350, "i" : 0, "t" : 0 }
 
// Query 3
//    Just changing the data type of d from a Date to an Int stops causing error 10365
 
> db.test.find().hint({g:1,d:-1,s:-1,i:1,t:1}).min({g:1,d:ISODate('2013-01-01'),s:700,i:0,t:0}).max({g:1,d:1,s:{},i:1,t:1})
{ "_id" : ObjectId("5139406d0518ed58a08d64c0"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 700, "i" : 0, "t" : 0 }
{ "_id" : ObjectId("513940700518ed58a08d64c1"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 600, "i" : 0, "t" : 0 }
{ "_id" : ObjectId("513940740518ed58a08d64c2"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 500, "i" : 0, "t" : 0 }
{ "_id" : ObjectId("513941f60518ed58a08d64c9"), "g" : [ 1, 2 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 350, "i" : 0, "t" : 0 }
>

Thanks for all your help!

Comment by Aaron Staple [ 08/Mar/13 ]

Hi Carl - I don't think

{ $minElement:1 }

and

{ $maxElement:1 }

can be sent to the server in this form. From the shell I think you can do:

> db.test.find().hint({g:1,d:-1,s:-1,i:1,t:1}).min({g:1,d:new Date('2013-01-01'),s:700,i:0,t:0}).max({g:1,d:new Date('2013-01-01'),s:MinKey,i:MaxKey,t:MaxKey})

Comment by Carl Youngblood [ 08/Mar/13 ]

Here is a less messy copy and paste. Please note the only difference between query 1 and 2 is the change to the value of the d key in the max parameter.

// Query 1
db.test.find().hint(

{g:1,d:-1,s:-1,i:1,t:1}

).min(

{g:1,d:ISODate('2013-01-01'),s:700,i:0,t:0}

).max({g:1,d:ISODate('2013-01-01'),s:

{'$minElement':1}

,i:

{'$maxElement':1}

,t:{'$maxElement':1}})
error: {
"$err" : "requested keyPattern does not match specified keys",
"code" : 10365
}

// Query 2
db.test.find().hint(

{g:1,d:-1,s:-1,i:1,t:1}

).min(

{g:1,d:ISODate('2013-01-01'),s:700,i:0,t:0}

).max({g:1,d:1,s:

{'$minElement':1}

,i:

{'$maxElement':1}

,t:{'$maxElement':1}})

{ "_id" : ObjectId("5139406d0518ed58a08d64c0"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 700, "i" : 0, "t" : 0 } { "_id" : ObjectId("513940700518ed58a08d64c1"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 600, "i" : 0, "t" : 0 } { "_id" : ObjectId("513940740518ed58a08d64c2"), "g" : [ 1 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 500, "i" : 0, "t" : 0 } { "_id" : ObjectId("513941f60518ed58a08d64c9"), "g" : [ 1, 2 ], "d" : ISODate("2013-01-01T00:00:00Z"), "s" : 350, "i" : 0, "t" : 0 }
Comment by Carl Youngblood [ 07/Mar/13 ]

The ellipses everywhere are just from copy pasting from my shell, if it really bugs you I can edit them out.

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