Mac local installation of mongodb is unstable - issue seems to be around ipv6

Hi.

I am mongodb noob and have installed mongodb on a PC (no issues) and a Mac. I installed mongodb community edition 5.0 using BREW. I have a m1 Mac laptop

My mongoose connection to the mongodb server does not want to resolve the name ‘localhost’ in the connection string

error is Error: connect ECONNREFUSED ::1:27017
connection string is MONGO_URI = mongodb://admin:admin@localhost:27017/iTunes?authSource=admin&retryWrites=true&w=majority

things I’ve tried:
stopping the brew service and running mongod --ipv6 --dbpath /path-to-database/

I got errors about Bootstrap which I didn’t understand.

I uninstalled mongodb through brew and reinstalled it (not understanding why it installed mongodb 4 first, then mongodb 5.0 - both community editions)

I restated using brew services start mongodb-community@5.0 and to my surprise all the collections from before were there, as was the ‘admin’ user

I was able to connect using my connection string (mongodb://admin:admin@localhost:27017/iTunes?authSource=admin&retryWrites=true&w=majority) and once I saw it was working I ran some calls to the API I built and tired I stopped and closed the app.

I returned later and I can no longer connect. I’ve seen so many error messages my head is spinning - is there something I can get the terminal to output so I can get some help?

Is there any information missing about my setup that I can provide?

thanks in advance.

Possibly mongod is listening on the external interface and not on localhost. Check your config.

thanks - this is my config

systemLog:
  destination: file
  path: /opt/homebrew/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /opt/homebrew/var/mongodb
net:
  bindIp: 127.0.0.1
  ipv6: true

I added the ipv6 switch.

I have read that I can also use ::,127.0.0.1 for the bindIp option.
It is supposed to open up the ipv6 resolution to the 127.0.0.1 IP address.

other errors I have searched on have been the following - mostly pulled from running as root in the terminal and getting lots of traces:

what I find really interesting is that after uninstalling and reinstalling it worked first try after being launched from BREW. if the issue was ipv6 based it should not have been able to resolve the ‘localhost’ in my connection string.

the error with the .plist makes me think that after running once mongodb wrote some config stuff and it is now jammed up and won’t accept connections going forward from that point.

to be clear I can connect via MONGOSH and can see the db’s and collections in the shell. it is just this page using mongoose that is failing - MongooseServerSelectionError: connect ECONNREFUSED ::1:27017

sudo rm /tmp/mongodb-27017.sock and try to make sure you always shut down cleanly.

thanks Jack. This was one of the solutions I tried yesterday (and just now) it seems not to make a difference. Do you think my .conf file looks OK? Should I maybe be binding to ::,127.0.0.1 to accommodate ipv6? I am just guessing here.

this is what the terminal outputs if I run mongod with --ipv6 and --dbpath options

seems to start chucking errors here [16514:0x2055fe600], wiredtiger_open: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 808: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}

I am not sure what wild tiger is.

ed@edwards-Air itunes_restfulapi % mongod --ipv6 --dbpath /opt/homebrew/var/mongodb
{“t”:{"$date":“2022-06-24T10:04:57.284+01:00”},“s”:“I”, “c”:“CONTROL”, “id”:23285, “ctx”:"-",“msg”:“Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’”}
{“t”:{"$date":“2022-06-24T10:04:57.285+01:00”},“s”:“I”, “c”:“NETWORK”, “id”:4915701, “ctx”:"-",“msg”:“Initialized wire specification”,“attr”:{“spec”:{“incomingExternalClient”:{“minWireVersion”:0,“maxWireVersion”:13},“incomingInternalClient”:{“minWireVersion”:0,“maxWireVersion”:13},“outgoing”:{“minWireVersion”:0,“maxWireVersion”:13},“isInternalClient”:true}}}
{“t”:{"$date":“2022-06-24T10:04:57.286+01:00”},“s”:“W”, “c”:“ASIO”, “id”:22601, “ctx”:“main”,“msg”:“No TransportLayer configured during NetworkInterface startup”}
{“t”:{"$date":“2022-06-24T10:04:57.286+01:00”},“s”:“I”, “c”:“NETWORK”, “id”:4648602, “ctx”:“main”,“msg”:“Implicit TCP FastOpen in use.”}
{“t”:{"$date":“2022-06-24T10:04:57.287+01:00”},“s”:“W”, “c”:“ASIO”, “id”:22601, “ctx”:“main”,“msg”:“No TransportLayer configured during NetworkInterface startup”}
{“t”:{"$date":“2022-06-24T10:04:57.288+01:00”},“s”:“I”, “c”:“REPL”, “id”:5123008, “ctx”:“main”,“msg”:“Successfully registered PrimaryOnlyService”,“attr”:{“service”:“TenantMigrationDonorService”,“ns”:“config.tenantMigrationDonors”}}
{“t”:{"$date":“2022-06-24T10:04:57.288+01:00”},“s”:“I”, “c”:“REPL”, “id”:5123008, “ctx”:“main”,“msg”:“Successfully registered PrimaryOnlyService”,“attr”:{“service”:“TenantMigrationRecipientService”,“ns”:“config.tenantMigrationRecipients”}}
{“t”:{"$date":“2022-06-24T10:04:57.288+01:00”},“s”:“I”, “c”:“CONTROL”, “id”:5945603, “ctx”:“main”,“msg”:“Multi threading initialized”}
{“t”:{"$date":“2022-06-24T10:04:57.288+01:00”},“s”:“I”, “c”:“CONTROL”, “id”:4615611, “ctx”:“initandlisten”,“msg”:“MongoDB starting”,“attr”:{“pid”:16514,“port”:27017,“dbPath”:"/opt/homebrew/var/mongodb",“architecture”:“64-bit”,“host”:“edwards-Air”}}
{“t”:{"$date":“2022-06-24T10:04:57.288+01:00”},“s”:“I”, “c”:“CONTROL”, “id”:23403, “ctx”:“initandlisten”,“msg”:“Build Info”,“attr”:{“buildInfo”:{“version”:“5.0.7”,“gitVersion”:“b977129dc70eed766cbee7e412d901ee213acbda”,“modules”:[],“allocator”:“system”,“environment”:{“distarch”:“x86_64”,“target_arch”:“x86_64”}}}}
{“t”:{"$date":“2022-06-24T10:04:57.288+01:00”},“s”:“I”, “c”:“CONTROL”, “id”:51765, “ctx”:“initandlisten”,“msg”:“Operating System”,“attr”:{“os”:{“name”:“Mac OS X”,“version”:“21.5.0”}}}
{“t”:{"$date":“2022-06-24T10:04:57.288+01:00”},“s”:“I”, “c”:“CONTROL”, “id”:21951, “ctx”:“initandlisten”,“msg”:“Options set by command line”,“attr”:{“options”:{“net”:{“ipv6”:true},“storage”:{“dbPath”:"/opt/homebrew/var/mongodb"}}}}
{“t”:{"$date":“2022-06-24T10:04:57.290+01:00”},“s”:“I”, “c”:“NETWORK”, “id”:5693100, “ctx”:“initandlisten”,“msg”:“Asio socket.set_option failed with std::system_error”,“attr”:{“note”:“acceptor TCP fast open”,“option”:{“level”:6,“name”:261,“data”:“00 04 00 00”},“error”:{“what”:“set_option: Invalid argument”,“message”:“Invalid argument”,“category”:“asio.system”,“value”:22}}}
{“t”:{"$date":“2022-06-24T10:04:57.291+01:00”},“s”:“I”, “c”:“NETWORK”, “id”:5693100, “ctx”:“initandlisten”,“msg”:“Asio socket.set_option failed with std::system_error”,“attr”:{“note”:“acceptor TCP fast open”,“option”:{“level”:6,“name”:261,“data”:“00 04 00 00”},“error”:{“what”:“set_option: Invalid argument”,“message”:“Invalid argument”,“category”:“asio.system”,“value”:22}}}
{“t”:{"$date":“2022-06-24T10:04:57.292+01:00”},“s”:“I”, “c”:“STORAGE”, “id”:22270, “ctx”:“initandlisten”,“msg”:“Storage engine to use detected by data files”,“attr”:{“dbpath”:"/opt/homebrew/var/mongodb",“storageEngine”:“wiredTiger”}}
{“t”:{"$date":“2022-06-24T10:04:57.292+01:00”},“s”:“I”, “c”:“STORAGE”, “id”:22315, “ctx”:“initandlisten”,“msg”:“Opening WiredTiger”,“attr”:{“config”:“create,cache_size=3584M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),builtin_extension_config=(zstd=(compression_level=6)),file_manager=(close_idle_time=600,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],”}}
{“t”:{"$date":“2022-06-24T10:04:57.394+01:00”},“s”:“E”, “c”:“STORAGE”, “id”:22435, “ctx”:“initandlisten”,“msg”:“WiredTiger error”,“attr”:{“error”:13,“message”:"[1656061497:394229][16514:0x2055fe600], wiredtiger_open: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 808: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}
{“t”:{"$date":“2022-06-24T10:04:57.395+01:00”},“s”:“E”, “c”:“STORAGE”, “id”:22435, “ctx”:“initandlisten”,“msg”:“WiredTiger error”,“attr”:{“error”:13,“message”:"[1656061497:395479][16514:0x2055fe600], wiredtiger_open: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char *, WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE **), 808: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}
{“t”:{"$date":“2022-06-24T10:04:57.395+01:00”},“s”:“E”, “c”:“STORAGE”, “id”:22435, “ctx”:“initandlisten”,“msg”:“WiredTiger error”,“attr”:{“error”:13,“message”:"[1656061497:395926][16514:0x2055fe600], wiredtiger_open: int __posix_open_file(WT_FILE_SYSTEM *, WT_SESSION *, const char , WT_FS_OPEN_FILE_TYPE, uint32_t, WT_FILE_HANDLE ), 808: /opt/homebrew/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}}
{“t”:{"$date":“2022-06-24T10:04:57.395+01:00”},“s”:“W”, “c”:“STORAGE”, “id”:22347, “ctx”:“initandlisten”,“msg”:“Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade.”}
{“t”:{"$date":“2022-06-24T10:04:57.395+01:00”},“s”:“F”, “c”:“STORAGE”, “id”:28595, “ctx”:“initandlisten”,“msg”:“Terminating.”,“attr”:{“reason”:“13: Permission denied”}}
{“t”:{"$date":“2022-06-24T10:04:57.395+01:00”},“s”:“F”, “c”:"-", “id”:23091, “ctx”:“initandlisten”,“msg”:“Fatal assertion”,“attr”:{“msgid”:28595,“file”:“src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp”,“line”:687}}
{“t”:{"$date":“2022-06-24T10:04:57.396+01:00”},“s”:“F”, “c”:"-", “id”:23092, “ctx”:“initandlisten”,“msg”:"\n\n
aborting after fassert() failure\n\n"}
ed@edwards-Air itunes_restfulapi %

LOL I fixed this whole issue really simply. Thanks for the help everyone but I wasn’t thinking about ‘keeping it simple, stupid’

my issue was that mongodb was running fine on my PC (as localhost) and all attempts to do the same on my MAC laptop (m1 chip) were failing.

I realised that the simplest thing to do since my PC install was working fine was as follows:

  • give the PC a static IP address by telling my home network router to always assign the same IP address
  • make sure the mongod.cfg file was set up correctly (binding to 0.0.0.0 - accepting access from all IP addresses) and security authorisation was enabled
  • change the IP address in my mongoose connection string from 127.0.0.1 to the new static IP address that my PC has on the network e.g. 192.0.1.92

Now the PC and the MAC can both access the same mongodb instance using the same code to connect to the newly shared mongodb server on the PC. This is clearly the best solution. I’m sorry I did not learn what was up with the mongodb install on the m1 processor Mac laptop - I would have liked to help the community but I have little understanding of the errors it was chucking.

thanks to everyone who answered my original post. here is a link to the video I used to set up this solution, hopefully it will be helpful to someone else.

2 Likes

w/r/t the M1, did you try to manually start mongod or did you use the brew-recommended service startup?

originally I tried the BREW service, and then I tried directly using mongod.

Interestingly there were no issues before I added authentication to mongodb - I had added it on the P
C because ultimately in deployment I would need it but the authentication would not work and (from what I read) this is an ipv6 issue on Macs.

I uninstalled, and reinstalled (via BREW) and it worked once through the brew service but not after that. Honestly the decision to give the PC a static IP address was not only simple but also clearly the correct solution. I was being daft having two different DBs but I am new to this and it seemed obvious to have it installed locally until I thought about it and realised it was a poor solution and a shared networked instance is logically much better.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.