Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The node.js native mongodb driver returns an "not master" error when it run db.command({aggregate : ...})

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?

like image 902
ehkim1440 Avatar asked Sep 26 '26 21:09

ehkim1440


1 Answers

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.

like image 83
ehkim1440 Avatar answered Sep 29 '26 21:09

ehkim1440