summaryrefslogtreecommitdiff
path: root/jstests/aggregation/bugs/server14969.js
blob: 629e54505fcdd404f94a64ddfa86115be27fd4b2 (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
// Test dropping an index that is being used by an agg pipeline.
var coll = db.server14969;
var docsPerBatch = 3;
coll.drop();

// Initialize collection with eight 1M documents, and index on field "a".
var longString = new Array(1024 * 1024).join('x');
for (var i = 0; i < 100; ++i) {
    assert.writeOK(coll.insert({a: 1, bigField: longString}));
}
assert.commandWorked(coll.ensureIndex({a: 1}));

// Create pipeline that uses index "a", with a small initial batch size.
var cursor = coll.aggregate([{$match: {a: 1}}], {cursor: {batchSize: docsPerBatch}});
for (var i = 0; i < docsPerBatch; ++i) {
    assert(cursor.hasNext());
    assert.eq(1, cursor.next().a);
}

// Drop index "a".
assert.commandWorked(coll.dropIndex({a: 1}));

// Issue a getmore against agg cursor.  Note that it is not defined whether the server continues to
// generate further results for the cursor.
try {
    cursor.hasNext();
    cursor.next();
} catch (e) {
}

// Verify that the server hasn't crashed.
assert.commandWorked(db.adminCommand({ping: 1}));