summaryrefslogtreecommitdiff
path: root/jstests/aggregation/bugs/explain_options_helper.js
blob: 0834d56e4699dfa2346a3dae215f76c939b3c164 (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
// Test that the explain helper does not modify the options document passed to it.
// This test was designed to reproduce SERVER-32300".

(function() {
"use strict";

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

for (let i = 0; i < 10; ++i) {
    assert.writeOK(coll.insert({_id: i}));
}

const collation = {
    collation: {locale: "zh", backwards: false}
};

const firstResults = coll.aggregate([{$sort: {_id: 1}}], collation).toArray();
// Issue an explain in order to verify that 'collation' is not modified to include the explain
// flag.
assert.commandWorked(coll.explain().aggregate([], collation));

const secondResults = coll.aggregate([{$sort: {_id: 1}}], collation).toArray();
// Assert that the result didn't change after an explain helper is issued.
assert.eq(firstResults, secondResults);
}());