ERROR: TypeError: Parameter "url" must be a string, not function

Viewed 400

I am trying to set up my node js application to connect to a MongoDB Atlas database, I am using the full driver code which they have provided me with. But when I start the app I receive the following error:

(node:4195) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Parameter "url" must be a string, not function

Here is the code that I have for my app.js:

var express               = require("express"),
    app                   = express(),
    bodyParser            = require("body-parser"),
    mongoose              = require("mongoose"),
    method_override       = require("method-override");



// mongoose.connect("mongodb://localhost/art_eng");
app.use(bodyParser.urlencoded({extended: true}));
app.set("view engine", "ejs");
app.use(express.static(__dirname + "/public"));
app.use(method_override("_method"));


const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://boris:<passwordWasHere>@arteng-jvhbz.mongodb.net/test?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
  const collection = client.db("test").collection("devices");
  // perform actions on the collection object
  client.close();
});

And the portfolio page that I have that is connected to the database cannot load and times out. How can I fix it?

1 Answers

I was also facing the same issue but resolved.

Your password must not contains any character which is problematic while parsing. In my case it just solved by removing % character.

Related