diff options
author | Benety Goh <benety@mongodb.com> | 2014-02-06 11:52:13 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2014-02-07 13:16:44 -0500 |
commit | e01492875083bf30bba35b38a8a0301e66c422df (patch) | |
tree | 4f2c1e31f96ce38c9f07fdd148db6aaa8e9abe16 /jstests/fts_projection.js | |
parent | 795353195c696a95a6f18a4deb38dfb5ad588ab9 (diff) | |
download | mongo-e01492875083bf30bba35b38a8a0301e66c422df.tar.gz |
SERVER-12129 meta projection operator should overwrite fields
Diffstat (limited to 'jstests/fts_projection.js')
-rw-r--r-- | jstests/fts_projection.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/jstests/fts_projection.js b/jstests/fts_projection.js index 2ee915e1585..eb1e26ab4ed 100644 --- a/jstests/fts_projection.js +++ b/jstests/fts_projection.js @@ -6,7 +6,7 @@ t.drop(); db.adminCommand({setParameter: 1, newQueryFrameworkEnabled: true}); t.insert({_id: 0, a: "textual content"}); -t.insert({_id: 1, a: "additional content"}); +t.insert({_id: 1, a: "additional content", b: -1}); t.insert({_id: 2, a: "irrelevant content"}); t.ensureIndex({a:"text"}); @@ -18,12 +18,23 @@ assert.eq(results.length, 2); assert(results[0].score); assert(results[1].score); +// indexed by _id. +var scores = [0, 0, 0]; +scores[results[0]._id] = results[0].score; +scores[results[1]._id] = results[1].score; + // // Edge/error cases: // // Project text score into 2 fields. results = t.find({$text: {$search: "textual content -irrelevant"}}, {otherScore: {$meta: "textScore"}, score:{$meta: "textScore"}}).toArray(); +assert.eq(2, results.length); +for (var i = 0; i < results.length; ++i) { + assert.close(scores[results[i]._id], results[i].score); + assert.close(scores[results[i]._id], results[i].otherScore); +} + // printjson(results); // Project text score into "x.$" shouldn't crash @@ -31,7 +42,17 @@ assert.throws(function() { t.find({$text: {$search: "textual content -irrelevant // TODO: We can't project 'x.y':1 and 'x':1 (yet). -// TODO: Clobber an existing field and behave nicely. +// Clobber an existing field and behave nicely. +results = t.find({$text: {$search: "textual content -irrelevant"}}, + {b: {$meta: "textScore"}}).toArray(); +assert.eq(2, results.length); +for (var i = 0; i < results.length; ++i) { + assert.close(scores[results[i]._id], results[i].b, + i + ': existing field in ' + tojson(results[i], '', true) + + ' is not clobbered with score'); +} + +assert.neq(-1, results[0].b); // Don't crash if we have no text score. var results = t.find({a: /text/}, {score: {$meta: "textScore"}}).toArray(); |