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-06-06 17:16:50 -0400
commit5dfc754e10bc411b0d23b6ec1bdadfe3c72ad91c (patch)
tree47cf5f296edeef83b90725fc8d53bd0e5898e73e /jstests
parent3f661319e52ba6cc47155721320fe32791a09958 (diff)
downloadmongo-5dfc754e10bc411b0d23b6ec1bdadfe3c72ad91c.tar.gz
SERVER-13337 support queries with projections in the idhack runner
(cherry picked from commit 10d8b3d7984a4abf0d8f80562d426d2f5f0707c3) Conflicts: src/mongo/db/query/idhack_runner.cpp
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() );