我正在尝试使用mongodb作为服务,并开始使用heroku服务,即dashboard.heroku.com/apps/scaleqamongo/resources。我尝试了多个插件,他们称之为mongolab,mongohq。我创建数据库,然后尝试将该服务地址添加到我的应用程序中
db: 'mongodb://username:password@candidate.19.mongolayer.com:10292,candidate.18.mongolayer.com:10292/app25406086',
但它给了我错误
Error: Cannot determine state of server
Error: No replica set primary available for query with ReadPreference PRIMARY
at ReplSet.checkoutReader (/prod/app/dashboard/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/repl_set/repl_set.js:585:14)
at Cursor.nextObject (/prod/app/dashboard/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:723:48)
at Cursor.nextObject (/prod/app/dashboard/node_modules/mongoose/node_modules/mongodb/lib/mongodb/scope.js:22:20)
at Collection.findOne (/prod/app/dashboard/node_modules/mongoose/node_modules/mongodb/lib/mongodb/collection/query.js:157:10)
at /prod/app/dashboard/node_modules/connect-mongo/lib/connect-mongo.js:214:18
at MongoStore._get_collection (/prod/app/dashboard/node_modules/connect-mongo/lib/connect-mongo.js:148:21)
at MongoStore.get (/prod/app/dashboard/node_modules/connect-mongo/lib/connect-mongo.js:213:10)
at Object.session [as handle] (/prod/app/dashboard/node_modules/express/node_modules/connect/lib/middleware/session.js:311:11)
at next (/prod/app/dashboard/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at Object.methodOverride [as handle] (/prod/app/dashboard/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:48:5)
虽然我可以使用shell命令
连接到数据库mongo candidate.19.mongolayer.com:10292/app25406086 -u username -p password
有什么问题?为什么我无法连接?
答案 0 :(得分:0)
这是一个间歇性错误,在我启动服务器后出现了一段时间,但稍后就消失了。