summaryrefslogtreecommitdiff
path: root/jstests/core/sortl.js
blob: d0d94473460d85ae3826cdad92fa5c407224429d (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
// Tests equality query on _id with a sort, intended to be tested on both mongos and mongod. For
// SERVER-20641.
(function() {
'use strict';
var coll = db.sortl;
coll.drop();

assert.writeOK(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");

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();
})();