MongoNotConnectedError('运行操作前必须连接客户端');如何处理这个问题?

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

MongoNotConnectedError('运行操作前必须连接客户端');如何处理<a href=https://www.elefans.com/category/jswz/34/1686244.html style=这个问题?"/>

MongoNotConnectedError('运行操作前必须连接客户端');如何处理这个问题?

每次运行代码时都会收到以下错误消息:

G:\Web Development\Projects\simple-crud-server\node_modules\mongodb\lib\operations\execute_operation.js:23
            throw new error_1.MongoNotConnectedError('Client must be connected before running operations');
                  ^

MongoNotConnectedError: Client must be connected before running operations
    at executeOperationAsync (G:\Web Development\Projects\simple-crud-server\node_modules\mongodb\lib\operations\execute_operation.js:23:19)
    at G:\Web Development\Projects\simple-crud-server\node_modules\mongodb\lib\operations\execute_operation.js:12:45
    at maybeCallback (G:\Web Development\Projects\simple-crud-server\node_modules\mongodb\lib\utils.js:278:21)
    at executeOperation (G:\Web Development\Projects\simple-crud-server\node_modules\mongodb\lib\operations\execute_operation.js:12:38)
    at Collection.insertOne (G:\Web Development\Projects\simple-crud-server\node_modules\mongodb\lib\collection.js:145:57)       
    at G:\Web Development\Projects\simple-crud-server\index.js:38:43
    at Layer.handle [as handle_request] (G:\Web Development\Projects\simple-crud-server\node_modules\express\lib\router\layer.js:95:5)
    at next (G:\Web Development\Projects\simple-crud-server\node_modules\express\lib\router\route.js:144:13)
    at Route.dispatch (G:\Web Development\Projects\simple-crud-server\node_modules\express\lib\router\route.js:114:3)
    at Layer.handle [as handle_request] (G:\Web Development\Projects\simple-crud-server\node_modules\express\lib\router\layer.js:95:5) {
  [Symbol(errorLabels)]: Set(0) {}
}
[nodemon] app crashed - waiting for file changes before starting...

我正在尝试从客户端在数据库中设置数据。但是每次我得到上面的错误。 作为参考(如果有帮助),这是我创建并运行的种子文件:

我该如何解决这个错误?

回答如下:

更多推荐

MongoNotConnectedError('运行操作前必须连接客户端');如何处理这个问题?

本文发布于:2024-05-30 21:13:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:这个问题   如何处理   客户端   操作   MongoNotConnectedError

发布评论

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

>www.elefans.com

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