summaryrefslogtreecommitdiff
path: root/jstests/core/index_large_and_small_dates.js
blob: 66df2ac8661fa06d7091e12362727e5ffff12ce7 (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
(function() {
"use strict";
const coll = db.index_dates;
coll.drop();

// Min value for JS Date().
// @tags: [
//   sbe_incompatible,
// ]
const d1 = new Date(-8640000000000000);
assert.commandWorked(coll.insert({_id: 1, d: d1}));
// Max value for JS Date().
const d2 = new Date(8640000000000000);
assert.commandWorked(coll.insert({_id: 2, d: d2}));

assert.commandWorked(coll.insert({_id: 3, d: 100}));

function test() {
    const list = coll.find({d: {$type: "date"}}).sort({_id: 1}).toArray();
    assert.eq(2, list.length);
    assert.eq(list[0], {_id: 1, d: d1});
    assert.eq(list[1], {_id: 2, d: d2});
}

test();
// Testing index version 1.
assert.commandWorked(coll.createIndex({d: 1}, {v: 1}));
test();
assert.commandWorked(coll.dropIndex({d: 1}));
// Testing index version 2.
assert.commandWorked(coll.createIndex({d: 1}));
test();
})();