2018-04-11 14:09:01 -04:00
|
|
|
// Test explain of various operations against a non-existent database
|
|
|
|
|
(function() {
|
2019-07-26 18:20:35 -04:00
|
|
|
var explainMissingDb = db.getSiblingDB("explainMissingDb");
|
2018-04-11 14:09:01 -04:00
|
|
|
|
2019-07-26 18:20:35 -04:00
|
|
|
var explain;
|
|
|
|
|
var explainColl;
|
2018-04-11 14:09:01 -04:00
|
|
|
|
2019-07-26 18:20:35 -04:00
|
|
|
// .find()
|
|
|
|
|
explainMissingDb.dropDatabase();
|
|
|
|
|
explain = explainMissingDb.collection.explain("executionStats").find().finish();
|
|
|
|
|
assert.commandWorked(explain);
|
|
|
|
|
assert("executionStats" in explain);
|
2018-04-11 14:09:01 -04:00
|
|
|
|
2019-07-26 18:20:35 -04:00
|
|
|
// .count()
|
|
|
|
|
explainMissingDb.dropDatabase();
|
|
|
|
|
explain = explainMissingDb.collection.explain("executionStats").count();
|
|
|
|
|
assert.commandWorked(explain);
|
|
|
|
|
assert("executionStats" in explain);
|
2018-04-11 14:09:01 -04:00
|
|
|
|
2019-07-26 18:20:35 -04:00
|
|
|
// .remove()
|
|
|
|
|
explainMissingDb.dropDatabase();
|
|
|
|
|
explain = explainMissingDb.collection.explain("executionStats").remove({a: 1});
|
|
|
|
|
assert.commandWorked(explain);
|
|
|
|
|
assert("executionStats" in explain);
|
2018-04-11 14:09:01 -04:00
|
|
|
|
2019-07-26 18:20:35 -04:00
|
|
|
// .update() with upsert: false
|
|
|
|
|
explainMissingDb.dropDatabase();
|
|
|
|
|
explainColl = explainMissingDb.collection.explain("executionStats");
|
|
|
|
|
explain = explainColl.update({a: 1}, {b: 1});
|
|
|
|
|
assert.commandWorked(explain);
|
|
|
|
|
assert("executionStats" in explain);
|
2018-04-11 14:09:01 -04:00
|
|
|
|
2019-07-26 18:20:35 -04:00
|
|
|
// .update() with upsert: true
|
|
|
|
|
explainMissingDb.dropDatabase();
|
|
|
|
|
explainColl = explainMissingDb.collection.explain("executionStats");
|
|
|
|
|
explain = explainColl.update({a: 1}, {b: 1}, {upsert: true});
|
|
|
|
|
assert.commandWorked(explain);
|
|
|
|
|
assert("executionStats" in explain);
|
2018-04-11 14:09:01 -04:00
|
|
|
|
2019-07-26 18:20:35 -04:00
|
|
|
// .aggregate()
|
|
|
|
|
explainMissingDb.dropDatabase();
|
|
|
|
|
explain = explainMissingDb.collection.explain("executionStats").aggregate([{$match: {a: 1}}]);
|
|
|
|
|
assert.commandWorked(explain);
|
2018-04-11 14:09:01 -04:00
|
|
|
}());
|