summaryrefslogtreecommitdiff
path: root/jstests/core/min_max_hashed_index.js
blob: 511f5a9ae622a4747b901ff2a705ee9348cb9282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * Check that min() and max() work with a hashed index.
 */
(function() {
"use strict";

const coll = db.min_max_hashed_index;
coll.drop();
assert.commandWorked(coll.insert({a: "test"}));
assert.commandWorked(coll.createIndex({a: 1}));
const minWithNormalIndex = coll.find({}, {_id: 0}).min({a: -Infinity}).hint({a: 1}).toArray();
assert.eq(minWithNormalIndex, [{a: "test"}]);

assert.commandWorked(coll.createIndex({a: "hashed"}));
const minWithHashedIndex =
    coll.find({}, {_id: 0}).min({a: -Infinity}).hint({a: "hashed"}).toArray();
assert.eq(minWithHashedIndex, [{a: "test"}]);
})();