我使用代码集
连接我的mongo副本集var mongojs = require('mongojs'); var replicationSet = "primary:27017,secondary:27017"; var replicaSetName = "rs"; var readPreference = "nearest"; var readPreferenceTags = "dc:test"; var generateMongoUri = function (username, pswd, db, authdb) { var url = format("mongodb://%s:%s@%s/%s?authSource=%s&replicaSet=%s&readPreference=%s&readPreferenceTags=%s&connectTimeoutMS=%s&socketTimeoutMS=%s", username, pswd, replicationSet, db, authdb, replicaSetName, readPreference, readPreferenceTags, 5000, 5000); return url; }; var userurl = generateMongoUri(username,username, pswd, db, authdb); var db = mongojs(userurl);
不经常但有时我得到此错误并且我的节点崩溃,我甚至不理解为什么会出现此错误
E:\NodeServer\node_modules\mongodb\lib\db.js:309
handleCallback(callback, null, result.result);
^
TypeError: Cannot read property 'result' of undefined
at E:\NodeServer\V122\node_modules\mongodb\lib\db.js:309:42
at ReplSet.command (E:\NodeServer\V122\node_modules\mongodb-core\lib\topologies\replset.js:1094:
42)
at ReplSet.command (E:\NodeServer\V122\node_modules\mongodb\lib\replset.js:388:18)
at Store.execute (E:\NodeServer\V122\node_modules\mongodb\lib\topology_base.js:108:30)
at done (E:\NodeServer\V122\node_modules\mongodb-core\lib\topologies\replset.js:267:40)
at null.<anonymous> (E:\NodeServer\V122\node_modules\mongodb-core\lib\topologies\replset.js:342:
9)
at g (events.js:260:16)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
at E:\NodeServer\V122\node_modules\mongodb-core\lib\topologies\server.js:283:14
at E:\NodeServer\V122\node_modules\mongodb-core\lib\connection\pool.js:436:18
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
有人能告诉我这个错误会在什么情况下弹出???