gpt4 book ai didi

node.js - 无法使用 Node.js 连接到 MongoDB

转载 作者:太空宇宙 更新时间:2023-11-04 00:22:48 25 4
gpt4 key购买 nike

无法使用 Node.js 连接到 MongoDB。

这是我的代码(mdb.js):

var MongoClient = require('mongodb').MongoClient, format = require('util').format;

MongoClient.connect('mongodb://localhost:3000', function(err,db){

if(err){
throw err;
} else {
console.log("Connected");
}
db.close();
});

node mdb.js 打印 MongoError:

enter image description here

最佳答案

当我将“localhost”更改为 127.0.0.1 时,它对我有用

关于node.js - 无法使用 Node.js 连接到 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43949066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com