node.js 在连接到 mongodb atlas 时挂起

编程入门 行业动态 更新时间:2024-10-04 01:18:19

node.js 在<a href=https://www.elefans.com/category/jswz/34/1771407.html style=连接到 mongodb atlas 时挂起"/>

node.js 在连接到 mongodb atlas 时挂起

我在连接到本地 MongoDB 时遇到问题,所以我想尝试连接到 atlas 数据库。仍然没有运气。我认为问题出在此时我的 Windows 安装上。

我可以使用相同的 uri 毫无问题地使用 MongoDB Compass 进行连接。

不会抛出任何错误。只是挂起。

const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://user:[email protected]/?retryWrites=true&w=majority";

MongoClient.connect(uri, function(err, db) {
  if (err) throw err;
  console.log('Connected to database!');

  // Perform database operations here...

  db.close(); 
});

如果您想了解我一直在处理的事情,请查看我以前的帖子。

我尝试禁用我的防火墙和 Windows Defender。 我确保用户名和密码周围没有< >。 我也试过猫鼬。

回答如下:

问题是,来自 npm 的较新的 mongodb 包不再执行/调用提供的回调。

MongoClient.connect(...)
而是返回一个承诺。

这是一个突破性的变化。

更多推荐

node.js 在连接到 mongodb atlas 时挂起

本文发布于:2024-05-31 02:24:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   挂起   js   node   mongodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!