mongo.isConnected 节点驱动程序 v4+ 的替代方案
原生 Node JS MongoDB 驱动程序中已弃用的 MongoClient.isConnected 是否有任何替代方案?
我在某处读到可以通过以下方式处理检查回调,可以在 .connect 方法中作为参数传递 (请参阅文档。) 但是,我没能成功做到这一点。
Is there any alternative for the deprecated MongoClient.isConnected in the native Node JS MongoDB driver?
I read somewhere that one can handle the check via callbacks, which one can pass as parameters in the .connect Method (See the docs.)
However, I wasn't able to successfully do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 mongoose.connect() 方法连接到 MongoDB。
使用 npm 从命令行安装 Mongoose:
请参阅我的 MongoDB + Node 示例:
https://github.com/juhisri211/node-mongo-app/blob/master/index.js
有关 Mongoose 的更多详细信息,请参考官方文档:
https://mongoosejs.com/docs/index.html
You can connect to MongoDB with the mongoose.connect() method.
Install Mongoose from the command line using npm:
Refer to my MongoDB + Node example:
https://github.com/juhisri211/node-mongo-app/blob/master/index.js
For more details about Mongoose, please refer to official documentation:
https://mongoosejs.com/docs/index.html