我正在尝试将 mongodb 用作服务并从 heroku 服务开始,即dashboard.heroku.com/apps/scaleqamongo/resources。我尝试了多个他们称之为 mongolab、mongohq 的插件。我创建数据库,然后尝试将该服务地址添加到我的应用程序中
db: 'mongodb://username:[email protected]: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
问题是什么?为什么我无法连接?
这是 Mongoose 驱动程序/ODM 的错误。
试试这个(取自文档):