微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用mongo localhost的本地数据库不起作用

如何解决使用mongo localhost的本地数据库不起作用

我正在尝试使localhost MongoDB DB工作,但我不明白。 我使用Mac。

这是我在shell(zsh)中写的内容

mongo

我收到此错误

MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: Couldn't connect to server 127.0.0.1:27017,connection attempt Failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:362:17
@(connect):2:6
exception: connect Failed
exiting with code 1

此外,当我写这篇文章时:

mongod

我明白了:

{"t":{"$date":"2020-09-07T12:01:27.943+02:00"},"s":"I","c":"CONTROL","id":23285,"ctx":"main","msg":"Automatically disabling TLS 1.0,to force-enable TLS 1.0 specify --ssldisabledProtocols 'none'"}
{"t":{"$date":"2020-09-07T12:01:27.945+02:00"},"s":"W","c":"ASIO","id":22601,"msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-07T12:01:27.945+02:00"},"c":"NETWORK","id":4648602,"msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"c":"STORAGE","id":4615611,"ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":2652,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"MBP-de-Gaetan"}}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"id":23403,"msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":["enterprise"],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"id":51765,"msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"19.6.0"}}}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"id":21951,"msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2020-09-07T12:01:27.947+02:00"},"s":"E","id":23024,"msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}
{"t":{"$date":"2020-09-07T12:01:27.947+02:00"},"s":"F","c":"-","id":23091,"msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":919}}
{"t":{"$date":"2020-09-07T12:01:27.947+02:00"},"id":23092,"msg":"\n\n***aborting after fassert() failure\n\n"}

当我尝试连接到本地数据库时,它也不适用于节点。 最终,我想使用“ Dotenv”通过节点连接到本地数据库 和这行代码: DATABASE = mongodb:// localhost:27017 / node-form

但我再次遇到错误

mongodb://localhost:27017/node-form
-: Connection error: connect ECONNREFUSED 127.0.0.1:27017 :-
(node:2930) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at new MongooseServerSelectionError (/Users/gaetan/WorkSpace/Back et front/Back/Fichiers_de_cours/node-forms_4/node_modules/mongoose/lib/error/serverSelection.js:24:11)
    at NativeConnection.Connection.openUri (/Users/gaetan/WorkSpace/Back et front/Back/Fichiers_de_cours/node-forms_4/node_modules/mongoose/lib/connection.js:823:32)
    at Mongoose.connect (/Users/gaetan/WorkSpace/Back et front/Back/Fichiers_de_cours/node-forms_4/node_modules/mongoose/lib/index.js:333:15)
    at Object.<anonymous> (/Users/gaetan/WorkSpace/Back et front/Back/Fichiers_de_cours/node-forms_4/start.js:8:10)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
(node:2930) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2930) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这里有另一个端口:

gaetan@MacBook-Pro-de-Gaetan ~ % mongod --port 27018
{"t":{"$date":"2020-09-07T12:18:16.133+02:00"},to force-enable TLS 1.0 specify --ssldisabledProtocols 'none'"}
{"t":{"$date":"2020-09-07T12:18:16.133+02:00"},"msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-07T12:18:16.133+02:00"},"msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-09-07T12:18:16.135+02:00"},"msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-07T12:18:16.136+02:00"},"attr":{"pid":2944,"port":27018,"host":"MacBook-Pro-de-Gaetan.local"}}
{"t":{"$date":"2020-09-07T12:18:16.136+02:00"},"target_arch":"x86_64"}}}}
{"t":{"$date":"2020-09-07T12:18:16.136+02:00"},"version":"19.6.0"}}}
{"t":{"$date":"2020-09-07T12:18:16.136+02:00"},"attr":{"options":{"net":{"port":27018}}}}
{"t":{"$date":"2020-09-07T12:18:16.137+02:00"},"id":20557,"msg":"DBException in initAndListen,terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option,or (2) by adding the 'storage.dbPath' option in the configuration file."}}
{"t":{"$date":"2020-09-07T12:18:16.137+02:00"},"id":20562,"msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2020-09-07T12:18:16.137+02:00"},"id":20520,"msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2020-09-07T12:18:16.137+02:00"},"id":20565,"msg":"Now exiting"}
{"t":{"$date":"2020-09-07T12:18:16.137+02:00"},"id":23138,"msg":"Shutting down","attr":{"exitCode":100}}

另外,它不在任何地方运行:

gaetan@MacBook-Pro-de-Gaetan ~ % sudo killall mongod
Password:
No matching processes were found
gaetan@MacBook-Pro-de-Gaetan ~ % sudo killall mongo 
No matching processes were found
gaetan@MacBook-Pro-de-Gaetan ~ % sudo killall mongodb
No matching processes were found
gaetan@MacBook-Pro-de-Gaetan ~ % 

解决方法

尝试在“ MongoDB”安装目录下的数据目录中创建一个新的“ db”和“ log”目录,并在“ log”目录下创建一个新的“ mongo.log”文件

,

感谢您的回答。 但是我认为安装出现了问题。几个星期前,我格式化了mac并使用brew以干净的方式重新安装了所有内容。现在,一切正常。还是谢谢你

,

您可以在此处提供解决方案。 SocketException: Address already in use MONGODB

由于返回套接字错误,mongodb默认端口可能被另一服务使用,即使可能性很小。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。