Connection Node.js API to MongoDB -


i'm trying build api-rest on node.js. did 1 before, i'm unable connect mongodb database. database has auth process, somehow, credentials aren't working expected. can connect locally database them, not when trying remote connection.

i read while this, , seems that, due updates, connection string i'm trying use not working @ all. here's code:

config.js:

    module.exports = { port: process.env.port || xxxx,   db: process.env.mongodb || 'mongodb://user:password@[ip adresss]:[port]/[databasename]',   token_secret: process.env.token_secret || 'asecrettoken' } 

index.js:

    'use strict'  const mongoose = require('mongoose') const app = require('./app') const config = require ('./config')  mongoose.promise = global.promise; mongoose.connect(config.db, (err,res) => {   if(err){     return console.log(`error when connecting database: ${err}`)   }   console.log('connection mongo database successful...')    app.listen(config.port, () => {   console.log(`api rest running on [ip adress]:${config.port}`) }) }) 

i know that, always, might asked before, , guess must simplest thing of world, i'm stuck s***!

thanks in advance, guys!

edit: error log

(node:3169) deprecationwarning: `open()` deprecated in mongoose >= 4.11.0, use `openuri()` instead, or set `usemongoclient` option if using `connect()` or `createconnection()`. see http://mongoosejs.com/docs/connections.html#use-mongo-client db.prototype.authenticate method no longer available in next major release 3.x mongodb 3.6 allow auth against users in admin db , no longer allow multiple credentials on socket. please authenticate using mongoclient.connect auth credentials. error when connecting database: mongoerror: authentication failed. (node:3169) unhandledpromiserejectionwarning: unhandled promise rejection (rejection id: 1): mongoerror: authentication failed. 

mongoose.connect("mongodb://user:password@[ip adresss]:[port]/[databasename]",{auth:{authdb:"admin"}}, () => {}) 

try put option.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -