summaryrefslogtreecommitdiff
path: root/jstests/core/sorta.js
blob: 91f36ba3621eceb3bc4575ef7077a6d79edcf6e0 (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
// SERVER-2905 sorting with missing fields

(function() {
    'use strict';

    var coll = db.jstests_sorta;
    coll.drop();

    const docs = [
        {_id: 0, a: MinKey},
        {_id: 1, a: []},
        {_id: 2, a: []},
        {_id: 3, a: null},
        {_id: 4},
        {_id: 5, a: null},
        {_id: 6, a: 1},
        {_id: 7, a: [2]},
        {_id: 8, a: MaxKey}
    ];
    const bulk = coll.initializeUnorderedBulkOp();
    for (let doc of docs) {
        bulk.insert(doc);
    }
    assert.writeOK(bulk.execute());

    assert.eq(coll.find().sort({a: 1, _id: 1}).toArray(), docs);

    assert.commandWorked(coll.createIndex({a: 1, _id: 1}));
    assert.eq(coll.find().sort({a: 1, _id: 1}).toArray(), docs);
})();