var testDB = db.getSiblingDB("mr_db");
|
assert.commandWorked(testDB.dropDatabase());
|
var coll = testDB.getCollection("source_col");
|
|
function getLatestProfilerEntry(inputDb) {
|
var cursor = inputDb.system.profile.find();
|
return cursor.sort({$natural: -1}).next();
|
}
|
|
testDB.setProfilingLevel(2);
|
|
var mapFunction = function() {
|
emit(this.a, this.b);
|
};
|
|
var reduceFunction = function(a, b) {
|
return Array.sum(b);
|
};
|
|
coll.drop();
|
for (var i = 0; i < 3; i++) {
|
assert.writeOK(coll.insert({a: i, b: i}));
|
}
|
|
coll.mapReduce(mapFunction, reduceFunction, {query: {a: {$gte: 0}}, out: "out_col"});
|
|
var profileObj = getLatestProfilerEntry(testDB);
|
assert.eq(profileObj.ns, coll.getFullName(), tojson(profileObj));
|