【问题标题】:ERROR: TypeError: Parameter "url" must be a string, not function错误:TypeError:参数“url”必须是字符串,而不是函数
【发布时间】:2020-02-13 20:06:48
【问题描述】:

我正在尝试设置我的节点 js 应用程序以连接到 MongoDB Atlas 数据库,我正在使用他们提供给我的完整驱动程序代码。但是当我启动应用程序时,我收到以下错误:

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

这是我的 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();
});

而我连接到数据库的投资组合页面无法加载并超时。我该如何解决?

【问题讨论】:

    标签: node.js mongodb mongodb-atlas


    【解决方案1】:

    我也遇到了同样的问题,但已经解决了。

    您的密码不能包含任何在解析时有问题的字符。 在我的情况下,它只是通过删除 % 字符来解决。

    【讨论】:

      猜你喜欢
      • 2018-05-16
      • 2017-02-24
      • 2019-07-07
      • 2018-02-26
      • 2023-02-18
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      相关资源
      最近更新 更多