summaryrefslogtreecommitdiff
path: root/jstests/core/sort5.js
blob: be40802ade469d4eaebb1d7f0a223a2be66e34f3 (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
var t = db.sort5;
t.drop();

t.save({_id: 5, x: 1, y: {a: 5, b: 4}});
t.save({_id: 7, x: 2, y: {a: 7, b: 3}});
t.save({_id: 2, x: 3, y: {a: 2, b: 3}});
t.save({_id: 9, x: 4, y: {a: 9, b: 3}});

// test compound sorting
// @tags: [
//   sbe_incompatible,
// ]

assert.eq([4, 2, 3, 1],
          t.find().sort({"y.b": 1, "y.a": -1}).map(function(z) {
              return z.x;
          }),
          "A no index");
t.createIndex({"y.b": 1, "y.a": -1});
assert.eq([4, 2, 3, 1],
          t.find().sort({"y.b": 1, "y.a": -1}).map(function(z) {
              return z.x;
          }),
          "A index");
assert(t.validate().valid, "A valid");

// test sorting on compound key involving _id

assert.eq([4, 2, 3, 1],
          t.find().sort({"y.b": 1, _id: -1}).map(function(z) {
              return z.x;
          }),
          "B no index");
t.createIndex({"y.b": 1, "_id": -1});
assert.eq([4, 2, 3, 1],
          t.find().sort({"y.b": 1, _id: -1}).map(function(z) {
              return z.x;
          }),
          "B index");
assert(t.validate().valid, "B valid");