1

I am getting the below error while connect to mongoDB present in MongoLab using node.js.

Your environment has been set up for using Node.js 6.9.1 (x64) and npm.

C:\Users\User>cd C:\xampp\htdocs\fgd

C:\xampp\htdocs\fgd>node server
Server is running on the port8989
GET / 200 113.510 ms - 6352
GET /calendar/tcal.js 404 7.320 ms - 29
GET /calendar/tcal.js 404 1.024 ms - 29
GET /favicon.ico 404 0.845 ms - 24
passstring
Error: Username containing an unescaped at-sign
    at module.exports (C:\xampp\htdocs\fgd\node_modules\mongodb\lib\url_parser.j
s:59:13)
    at connect (C:\xampp\htdocs\fgd\node_modules\mongodb\lib\mongo_client.js:289
:16)
    at Function.MongoClient.connect (C:\xampp\htdocs\fgd\node_modules\mongodb\li
b\mongo_client.js:113:3)
    at C:\xampp\htdocs\fgd\node_modules\mongojs\lib\database.js:29:15
    at run (C:\xampp\htdocs\fgd\node_modules\thunky\index.js:13:3)
    at Collection._getConnection (C:\xampp\htdocs\fgd\node_modules\thunky\index.
js:27:3)
    at Collection._getCollection (C:\xampp\htdocs\fgd\node_modules\mongojs\lib\c
ollection.js:17:10)
    at getCursor (C:\xampp\htdocs\fgd\node_modules\mongojs\lib\collection.js:32:
10)
    at C:\xampp\htdocs\fgd\node_modules\mongojs\lib\cursor.js:12:5
    at run (C:\xampp\htdocs\fgd\node_modules\thunky\index.js:13:3)
POST /login 500 68.758 ms - 1001

Here is my code:

var mongoJs=require('mongojs');
var CryptoJS = require("crypto-js");
var database='FGDP';
var collections=['f_users'];
var MONGOLAB_URI="mongodb://subhra:******123@@ds127153.mlab.com:27153/fgdp";
var db=mongoJs(MONGOLAB_URI,collections);
var ses;
db.on('connect', function () {
    console.log('database connected')
});
halfer
  • 19,824
  • 17
  • 99
  • 186
satya
  • 3,508
  • 11
  • 50
  • 130

1 Answers1

0

Simply Use "mongodb://username:"+encodeURIComponent("p@ssword")+"@localhost:27017/database"