node.js - Bitnami Meanstack Mongoose Connection -
i created simple service in ubuntu 16.04 mongo db node , express return data angular 2 app.
i have file called server.js connects local mongodb instance database called game , collection called players. works fine installed on local machine. trying deploy bitnami's mean stack image on amazon ec2. (bleh mouth full). have set ports correctly according this guide, , can connect remotely. however, can't mongoose connect database. here code works on local machine.
mongoose.connect('mongodb://localhost:27017/game'); router.route('/player') .get(function(req, res) { console.log(mongoose.connection.readystate); player.find({"player":user,"password":password},function(err, test) { if (err) res.send(err); res.json(test); }); });
and here adjusted code mean stack image
mongoose.connect('mongodb://root:"my-root-password@127.0.0.1:27017/game'); router.route('/player') .get(function(req, res) { console.log(mongoose.connection.readystate); player.find({"player":user,"password":password},function(err, test) { if (err) res.send(err); res.json(test); }); });
on local machine value of 1 on console.log , value of 0 on mean stack image. i'm not sure how connect bitnami's mongo instance mongoose. have checked game exist , has data want.
i found fix although don't yet understand it. came guide posted here . first had un comment out section of mongodb.conf says noauth = true
comment out line says auth = true
. restart mongo, , create new user permissions read , write the data base want use this
db.createuser({ user: "new username", pwd: "new password", roles:[ { "role" : "readwrite", "db": "game" } ]})
after creating user undo did noauth = true
, auth = true
, , restart mongodb. able connect mongoose this
mongoose.connect('mongodb://new username:new password@127.0.0.1:27017/game');
Comments
Post a Comment