summaryrefslogtreecommitdiff
path: root/jstests/core/sortl.js
blob: 187130ffe586d9b63fe4d2b5fd933d1ab420d2b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Tests equality query on _id with a sort, intended to be tested on both mongos and mongod. For
// SERVER-20641.
//
// Always run on a fully upgraded cluster, so that {$meta: "sortKey"} projections use the newest
// sort key format.
// @tags: [requires_fcv_44]

(function() {
'use strict';
var coll = db.sortl;
coll.drop();

assert.commandWorked(coll.insert({_id: 1, a: 2}));
var res = coll.find({_id: 1}).sort({a: 1});
assert.eq(res.next(), {_id: 1, a: 2});
assert.eq(res.hasNext(), false);

res = coll.find({_id: 1}, {b: {$meta: "sortKey"}}).sort({a: 1});
assert.eq(res.next(), {_id: 1, a: 2, b: [2]});
assert.eq(res.hasNext(), false);

res = db.runCommand({
    findAndModify: coll.getName(),
    query: {_id: 1},
    update: {$set: {b: 1}},
    sort: {a: 1},
    fields: {c: {$meta: "sortKey"}}
});
assert.commandFailedWithCode(res, ErrorCodes.BadValue, "$meta sortKey update");

coll.drop();
assert.commandWorked(coll.insert({_id: 1, a: 2}));

res = db.runCommand({
    findAndModify: coll.getName(),
    query: {_id: 1},
    remove: true,
    sort: {b: 1},
    fields: {c: {$meta: "sortKey"}}
});
assert.commandFailedWithCode(res, ErrorCodes.BadValue, "$meta sortKey delete");

coll.drop();
})();