node.js - 未处理的拒绝 MongoError:必须指定端口
问题描述
根据Mongoose 文档,您可以使用默认端口 27017 连接到 MongoDB。
我的mongod
输出以:
I NETWORK [initandlisten] waiting for connections on port 27017
但是当我尝试像这样连接到我的数据库时:
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/myapp');
我明白了
Unhandled rejection MongoError: port must be specified
这里发生了什么?
我有 Mongoose v5.2.0、node v9.10.0 和 MongoDB shell 版本 v4.0.0。
如果我更改我的连接字符串以包含端口,mongodb://localhost:27017/myapp
那么我可以连接。但我不确定我为什么需要这个。
解决方案
Mongoose maintainer here, sorry about the trouble. We'll fix this issue within the next couple days. Until then, please specify the port in your URI: mongoose.connect('mongodb://localhost:27017/myapp');
. We'll also make sure to update the relevant docs.
推荐阅读
- php - 如何在 php 7 中修复 SOAP-ERROR 解析 wsdl
- sql - 对 postgresql 的约束
- javascript - 在模式上获取重复数据后,我可以使用编辑操作删除重复数据吗?
- javascript - Node js和socket io——预约系统
- node.js - 在nodemailer的文本部分添加各种字段
- pycharm - PyCharm 运行配置不在主窗口上
- sql - BigQuery SQL 查询需要 10 多分钟才能加载
- java - SonarQube 6.7.7 如何在不分析测试的情况下将junit测试计数添加到仪表板
- xml - 更新 WebServer 上的 XML - AppleScript Curl
- r - Is there a R function to print & export column names to excel?