Browse files

fix ClientCursor::getFieldsDotted with compound keys SERVER-2325

  • Loading branch information...
1 parent 86af56e commit 4b80354d2fdf18d187673631cee3755000784be8 @erh erh committed Jan 5, 2011
Showing with 38 additions and 1 deletion.
  1. +3 −1 db/clientcursor.cpp
  2. +35 −0 jstests/distinct_index2.js
View
4 db/clientcursor.cpp
@@ -301,8 +301,10 @@ namespace mongo {
int x = i->second;
BSONObjIterator it( currKey() );
- while ( x && it.more() )
+ while ( x && it.more() ){
it.next();
+ x--;
+ }
assert( x == 0 );
ret.insert( it.next() );
return true;
View
35 jstests/distinct_index2.js
@@ -0,0 +1,35 @@
+t = db.distinct_index2;
+t.drop();
+
+t.ensureIndex( { a : 1 , b : 1 } )
+t.ensureIndex( { c : 1 } )
+
+function x(){
+ return Math.floor( Math.random() * 10 );
+}
+
+for ( i=0; i<2000; i++ ){
+ t.insert( { a : x() , b : x() , c : x() } )
+}
+
+correct = []
+for ( i=0; i<10; i++ )
+ correct.push( i )
+
+function check( field ){
+ res = t.distinct( field )
+ res = res.sort()
+ assert.eq( correct , res , "check: " + field );
+
+ if ( field != "a" ){
+ res = t.distinct( field , { a : 1 } )
+ res = res.sort()
+ assert.eq( correct , res , "check 2: " + field );
+ }
+}
+
+check( "a" )
+check( "b" )
+check( "c" )
+
+

0 comments on commit 4b80354

Please sign in to comment.