summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/sort_big_documents_with_multi_planning.js
blob: a711654a736a32a3aa1bb8a9a9c42eec662397ef (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
45
46
// This test is designed to reproduce the test described in SERVER-65270, where a query
// which uses multi-planning and large documents does not respect the sort order.
(function() {
"use strict";

const coll = db.sort_big_documents_with_multi_planning;
coll.drop();

function makeDoc(i) {
    return {_id: i, filterKey: 1, num: i, bytes: BinData(0, "A".repeat(13981014) + "==")};
}

for (let i = 0; i < 10; i++) {
    assert.commandWorked(coll.insert(makeDoc(i)));
}

// Two possible indexes can answer the query.
assert.commandWorked(coll.createIndex({filterKey: 1, num: 1, foo: 1}));
assert.commandWorked(coll.createIndex({filterKey: 1, num: 1}));

const sortSpec = {
    num: 1
};

const kExpectedNums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

{
    // We do a "client side projection," to avoid printing out the massive BinData string if
    // there's an error.
    const nums = [];
    coll.find({filterKey: 1}).sort(sortSpec).forEach(doc => nums.push(doc.num));

    // The results should be in order.
    assert.eq(nums, kExpectedNums);
}

// Same test, but with aggregation.
{
    const nums = [];
    coll.aggregate([{$match: {filterKey: 1}}, {$sort: sortSpec}])
        .forEach(doc => nums.push(doc.num));

    // The results should be in order.
    assert.eq(nums, kExpectedNums);
}
})();