It's different that the result of mongoShell and node.js application. My mongodb environment uses shard cluster.
The result of mongoShell
mongos> db.runCommand({aggregate : "collection", pipeline : my_pipeline(), allowDiskUse : true});
{
"result" : [ ],
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1428399959, 408),
"electionId" : ObjectId("552363d7ddfce783509094e5")
}
}
The result of node.js application
var mongodb = require('mongodb');
var mongoClient = new mongodb.MongoClient(...);
mongoClient.open(function (err, mongoClient) {
var db = mongoClient.db(...);
db.command({aggregate : "collection", pipeline : my_pipeline(), allowDiskUse : true}, function (err) {
...
});
});
-->
MongoError: exception: failed to create temporary $out collection 'db.tmp.agg_out.12': { note: "from execCommand", ok: 0.0, errmsg: "not master" }
I want to execute aggregation framework query in node.js application.
How can I execute this query in application?