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
|
// Test inequality bounds combined with ordering for a single-field index.
// BUG 1079 (fixed)
// @tags: [
// assumes_read_concern_local,
// ]
testNum = 1;
function checkResults(expected, cursor, testNum) {
assert.eq(expected.length,
cursor.count(),
"testNum: " + testNum + " A : " + tojson(cursor.toArray()) + " " +
tojson(cursor.explain()));
for (i = 0; i < expected.length; ++i) {
assert.eq(expected[i], cursor[i]["a"], "testNum: " + testNum + " B");
}
}
t = db.cursor3;
t.drop();
t.save({a: 0});
t.save({a: 1});
t.save({a: 2});
t.createIndex({a: 1});
checkResults([1], t.find({a: 1}).sort({a: 1}).hint({a: 1}), testNum++);
checkResults([1], t.find({a: 1}).sort({a: -1}).hint({a: 1}), testNum++);
checkResults([1, 2], t.find({a: {$gt: 0}}).sort({a: 1}).hint({a: 1}), testNum++);
checkResults([2, 1], t.find({a: {$gt: 0}}).sort({a: -1}).hint({a: 1}), testNum++);
checkResults([1, 2], t.find({a: {$gte: 1}}).sort({a: 1}).hint({a: 1}), testNum++);
checkResults([2, 1], t.find({a: {$gte: 1}}).sort({a: -1}).hint({a: 1}), testNum++);
checkResults([0, 1], t.find({a: {$lt: 2}}).sort({a: 1}).hint({a: 1}), testNum++);
checkResults([1, 0], t.find({a: {$lt: 2}}).sort({a: -1}).hint({a: 1}), testNum++);
checkResults([0, 1], t.find({a: {$lte: 1}}).sort({a: 1}).hint({a: 1}), testNum++);
checkResults([1, 0], t.find({a: {$lte: 1}}).sort({a: -1}).hint({a: 1}), testNum++);
|