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?
I resolved it myself through upgrading node.js mongodb driver.
I used mongodb driver that is version 1.4.29 in previous test.
In 1.4.29 version API, 'db.command' doesn't check read preference about slaves.
So when I run my application, I got a error like that.
After upgrading node.js mongodb driver to 2.0.27(latest) and custormizing my application to changed API, the application runs very well.
Thank you for your suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With