1
// Simple covered index query test with sort
3
var coll = db.getCollection("covered_sort_1")
14
coll.insert({foo:"1"})
15
coll.insert({foo:{bar:1}})
16
coll.insert({foo:null})
17
coll.ensureIndex({foo:1})
19
// Test no query and sort ascending
20
var plan = coll.find({}, {foo:1, _id:0}).sort({foo:1}).hint({foo:1}).explain()
21
assert.eq(true, plan.indexOnly, "sort.1.1 - indexOnly should be true on covered query")
22
assert.eq(0, plan.nscannedObjects, "sort.1.1 - nscannedObjects should be 0 for covered query")
24
// Test no query and sort descending
25
var plan = coll.find({}, {foo:1, _id:0}).sort({foo:-1}).hint({foo:1}).explain()
26
assert.eq(true, plan.indexOnly, "sort.1.2 - indexOnly should be true on covered query")
27
assert.eq(0, plan.nscannedObjects, "sort.1.2 - nscannedObjects should be 0 for covered query")
29
// Test range query with sort
30
var plan = coll.find({foo:{$gt:2}}, {foo:1, _id:0}).sort({foo:-1}).hint({foo:1}).explain()
31
assert.eq(true, plan.indexOnly, "sort.1.5 - indexOnly should be true on covered query")
32
assert.eq(0, plan.nscannedObjects, "sort.1.5 - nscannedObjects should be 0 for covered query")
34
print ('all tests pass')
b'\\ No newline at end of file'