summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-04-28 16:39:33 -0400
committerDavid Storch <david.storch@10gen.com>2014-05-01 09:17:40 -0400
commit10d8b3d7984a4abf0d8f80562d426d2f5f0707c3 (patch)
tree44707d2d393fe693955224a62503e0c509373cd3 /jstests
parent5b4ad3281493f6fcdccf96781237e79a13b59621 (diff)
downloadmongo-10d8b3d7984a4abf0d8f80562d426d2f5f0707c3.tar.gz
SERVER-13337 support queries with projections in the idhack runner
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/idhack.js40
1 files changed, 33 insertions, 7 deletions
diff --git a/jstests/core/idhack.js b/jstests/core/idhack.js
index 311c4ebc935..11fb1e0f447 100644
--- a/jstests/core/idhack.js
+++ b/jstests/core/idhack.js
@@ -46,14 +46,40 @@ var skipExplain = t.find( query ).skip(1).explain();
print( "explain for skip query = " + tojson( skipExplain ) );
assert.neq( explain.cursor, skipExplain.cursor, "F1" );
-// Only acceptable projection for ID hack is {_id: 1}.
-var projectionExplain = t.find( query, { _id : 0, z : 1 } ).explain();
-print( "explain for projection query = " + tojson( projectionExplain ) );
-assert.neq( explain.cursor, projectionExplain.cursor, "G1" );
-
// Covered query returning _id field only can be handled by ID hack.
var coveredExplain = t.find( query, { _id : 1 } ).explain();
print( "explain for covered query = " + tojson( coveredExplain ) );
-assert.eq( explain.cursor, coveredExplain.cursor, "H1" );
+assert.eq( explain.cursor, coveredExplain.cursor, "G1" );
// Check doc from covered ID hack query.
-assert.eq( { _id : { x: 2 } }, t.findOne( query, { _id : 1 } ), "H2" );
+assert.eq( { _id : { x: 2 } }, t.findOne( query, { _id : 1 } ), "G2" );
+
+//
+// Non-covered projection for idhack.
+//
+
+t.drop();
+t.insert( { _id: 0, a: 0, b: [ { c: 1 }, { c: 2 } ] });
+t.insert( { _id: 1, a: 1, b: [ { c: 3 }, { c: 4 } ] });
+
+// Simple inclusion.
+assert.eq( { _id: 1, a: 1 }, t.find( { _id: 1 }, { a: 1 } ).next() );
+assert.eq( { a: 1 }, t.find({ _id: 1 }, { _id: 0, a: 1 } ).next() );
+assert.eq( { _id: 0, a: 0 }, t.find( { _id: 0 }, { _id: 1, a: 1 } ).next() );
+
+// Non-simple: exclusion.
+assert.eq( { _id: 1, a: 1 }, t.find( { _id: 1 }, { b: 0 } ).next() );
+assert.eq( { _id: 0, }, t.find( { _id: 0 }, { a: 0, b: 0 } ).next() );
+
+// Non-simple: dotted fields.
+assert.eq( { b: [ { c: 1 }, { c: 2 } ] }, t.find( { _id: 0 }, { _id: 0, "b.c": 1 } ).next() );
+assert.eq( { _id: 1 }, t.find( { _id: 1 }, { "foo.bar": 1 } ).next() );
+
+// Non-simple: elemMatch projection.
+assert.eq( { _id: 1, b: [ { c: 4 } ] },
+ t.find( { _id: 1 }, { b: { $elemMatch: { c: 4 } } } ).next() );
+
+// Non-simple: $returnKey.
+assert.eq( { _id: 1 }, t.find( { _id: 1 } )._addSpecial( "$returnKey", true ).next() );
+
+// Non-simple: $returnKey overrides other projections.
+assert.eq( { _id: 1 }, t.find( { _id: 1 }, { a: 1 } )._addSpecial( "$returnKey", true ).next() );