1

I'm a beginner in this area and i can not find any solution to this problem. I'm bulding a chat app in Node.js using MongoLabs Database services. I'm trying to connect to mongoDB with mongoose@3.8.10 driver. I've checked many times, everything is fine but i still get the "Auth Failed Error Code 18".

Here's my package.json

  dependencies: {
    "connect-mongo": "^0.4.1",
    "cookie-parser": "^1.1.0",
    "express": "^4.2.0",
    "express-session": "^1.2.0",
    "hogan-express": "^0.5.2",
    "mongoose": "^3.8.10",
    "passport": "^0.2.0",
    "passport-facebook": "^1.0.3",
    "socket.io": "^0.9.17"
  }

I've referred to mongoose docs for a better understanding of "How to connect to MonoDB by using Mongoose as a driver". But I could not find a solution. Here's my code with which I'm trying to connect:

var express = require('express'),

app     = express(),

path    =   require('path'),

config  = require('./config/config.js'),

session = require('express-session'),

ConnectMongo = require('connect-mongo')(session),

mongoose = require('mongoose'),

passport = require('passport'),

FacebookStrategy = require('passport-facebook').Strategy;



var db = mongoose.connect(config.dbURL);

mongoose.connect(config.dbURL, function (err, res) { 
  if (err) { 
           console.log ('ERROR connecting to: ' + config.dbURL + '. ' + err + '----- db =' +  db );
   } else {  console.log ('Succeeded connected to: ' + config.dbURL); 
   }
  });

config.dbURL is the url i got from mongoLab and it is like this:

   'mongodb://{DBuser}:{DBpswrd}@ds0{port}.mongolab.com:{port}/{dbName}'
Tahir Raza
  • 726
  • 1
  • 7
  • 20
  • I'm getting this output on console: connection error: { [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 } – Tahir Raza Oct 12 '15 at 13:15
  • Perhaps this helps: http://stackoverflow.com/questions/23721866/mongodb-2-6-1-command-line-authentication-fails – MeBNoah Oct 12 '15 at 14:07

1 Answers1

1

It looks like you're using a MongoLab Sandbox database, which runs MongoDB 3.0 with SCRAM-SHA-1.

You'll have to update your Mongoose driver to a later version that uses version 1.4.29 or greater of the underlying Node.js driver per the MongoDB 3.0-SCRAM docs.

Chris Chang
  • 426
  • 1
  • 3
  • 7
  • i have updated the driver and auth problem is fixed now it is saying that Failed to set TTL index please have a look at the error screenshot http://prntscr.com/8rmei0 – Tahir Raza Oct 15 '15 at 16:05
  • I'm guessing the TTL index is for a session store. You can try deleting that collection and/or upgrading that session management library version to a more recent version. – Chris Chang Oct 19 '15 at 20:19