summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/find_and_modify.js35
-rw-r--r--jstests/core/find_projection_meta_errors.js3
-rw-r--r--jstests/core/fts_projection.js12
3 files changed, 31 insertions, 19 deletions
diff --git a/jstests/core/find_and_modify.js b/jstests/core/find_and_modify.js
index 83e1e7da79d..8f437726c51 100644
--- a/jstests/core/find_and_modify.js
+++ b/jstests/core/find_and_modify.js
@@ -33,6 +33,32 @@ out = t.findAndModify(
{query: {inprogress: false}, sort: {priority: -1}, update: {$set: {inprogress: true}}});
assert.eq(out.priority, 9);
+// Use expressions in the 'fields' argument with 'new' false.
+out = t.findAndModify({
+ query: {inprogress: false},
+ sort: {priority: -1},
+ 'new': false,
+ update: {$set: {inprogress: true}, $inc: {value: 1}},
+ fields: {priority: 1, inprogress: 1, computedField: {$add: ["$value", 2]}}
+});
+assert.eq(out.priority, 8);
+assert.eq(out.inprogress, false);
+// The projection should have been applied to the pre image of the update.
+assert.eq(out.computedField, 2);
+
+// Use expressions in the 'fields' argument with 'new' true.
+out = t.findAndModify({
+ query: {inprogress: false},
+ sort: {priority: -1},
+ update: {$set: {inprogress: true}, $inc: {value: 1}},
+ 'new': true,
+ fields: {priority: 1, inprogress: 1, computedField: {$add: ["$value", 2]}}
+});
+assert.eq(out.priority, 7);
+assert.eq(out.inprogress, true);
+// The projection should have been applied to the update post image.
+assert.eq(out.computedField, 3);
+
// remove lowest priority
out = t.findAndModify({sort: {priority: 1}, remove: true});
assert.eq(out.priority, 1);
@@ -122,15 +148,6 @@ cmdRes = db.runCommand({
});
assert.commandFailed(cmdRes);
-// Cannot use expressions in the projection part of findAndModify.
-cmdRes = db.runCommand({
- findAndModify: "coll",
- update: {a: 1},
- fields: {b: {$ln: ['c']}},
- upsert: true,
-});
-assert.commandFailedWithCode(cmdRes, ErrorCodes.BadValue);
-
//
// SERVER-17372
//
diff --git a/jstests/core/find_projection_meta_errors.js b/jstests/core/find_projection_meta_errors.js
index bab64b816b6..ea6206c4703 100644
--- a/jstests/core/find_projection_meta_errors.js
+++ b/jstests/core/find_projection_meta_errors.js
@@ -10,6 +10,5 @@ assert.commandWorked(coll.insert({a: 1}));
assert.commandWorked(coll.insert({a: 2}));
assert.commandFailedWithCode(
- db.runCommand({find: coll.getName(), projection: {score: {$meta: "some garbage"}}}),
- ErrorCodes.BadValue);
+ db.runCommand({find: coll.getName(), projection: {score: {$meta: "some garbage"}}}), 17308);
}());
diff --git a/jstests/core/fts_projection.js b/jstests/core/fts_projection.js
index f021ce04298..45ca86bcd89 100644
--- a/jstests/core/fts_projection.js
+++ b/jstests/core/fts_projection.js
@@ -29,15 +29,17 @@ scores[results[1]._id] = results[1].score;
// Edge/error cases:
//
-// Project text score into 2 fields.
+// Project text score into 3 fields, one nested.
results = t.find({$text: {$search: "textual content -irrelevant"}}, {
otherScore: {$meta: "textScore"},
- score: {$meta: "textScore"}
+ score: {$meta: "textScore"},
+ "nestedObj.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);
+ assert.close(scores[results[i]._id], results[i].nestedObj.score);
}
// printjson(results);
@@ -66,12 +68,6 @@ 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();
-// printjson(results);
-
-// No textScore proj. with nested fields
-assert.throws(function() {
- t.find({$text: {$search: "blah"}}, {'x.y': {$meta: "textScore"}}).toArray();
-});
// SERVER-12173
// When $text operator is in $or, should evaluate first