【发布时间】: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