[SERVER-1366] $in operator not behaving as expect in compound key scenarios Created: 06/Jul/10 Updated: 06/Jul/10 Resolved: 06/Jul/10 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 1.4.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Torsten Curdt | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Participants: |
| Description |
|
I have a compound key. Searching it directly works just fine. find({_id : { a:'1', b:'2' }}) -> 1 doc As I want to get a couple of documents in on query, varying on the second part of the key I tried find({_id : { a:'1', b: { $in: ['2'] }}) -> 0 docs while this was expected to give the very same result. After lots of tries I found that only find({ _id: { $in: [ { a: '1', b: '2' }] ]}) -> 1 docs works. Which essentially means one needs to send a lot of duplicated data in a query. find({ _id: { $in: [ { a: '1', b: '1' }, { a: '1', b: '2' }, { a: '1', b: '3' }, { a: '1', b: '4' }] ]}) -> 4 docs Even worse - there is no error message or reason given why the $in operator does not work in compound keys. Could be related to http://jira.mongodb.org/browse/SERVER-1026 |
| Comments |
| Comment by Torsten Curdt [ 06/Jul/10 ] |
|
Well, I would vote for that error. Arguing from a users perspective it's not that clear why it should not be allowed in that context. |
| Comment by Eliot Horowitz (Inactive) [ 06/Jul/10 ] |
|
$in is a query operator in the right context. we do say fields can't start with $, so that makes it unable to be saved, so perhaps there could be an error because of that, but not sure |
| Comment by Torsten Curdt [ 06/Jul/10 ] |
|
but $in is a query operator |
| Comment by Eliot Horowitz (Inactive) [ 06/Jul/10 ] |
|
Its valid syntax, just wrong. } |
| Comment by Torsten Curdt [ 06/Jul/10 ] |
|
So if that syntax I gave is not supported ...shouldn't that give an error? I am confused why that needs a separate index though. ...and I am amazed how quickly this issue got attention |
| Comment by auto [ 06/Jul/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: fix |
| Comment by Aaron Staple [ 06/Jul/10 ] |
|
That won't use the _id index - you would need an index on {_id.a:1,_id.b:1} |
| Comment by Aaron Staple [ 06/Jul/10 ] |
|
find({_id : { a:'1', b: { $in: ['2'] }}) We don't support this syntax at all. You want {'_id.a':'1','_id.b':{$in:['2']}}. |
| Comment by Eliot Horowitz (Inactive) [ 06/Jul/10 ] |
|
See jstests/in5.js |