[Solved] Mongo listening on unix socket ?

Technical Support
  • Hello all !

    Just a quick question... I have my mongo db listening on a unix socket (/var/run/mongodb/mongodb-27017.sock) and I want nodebb to connect to this socket instead of using the network, is this possible ?

    I have tried so many combinations of host/port/uri in the config.json file but still no luck.

    The mongo db is accessible from this socket:

    [email protected] ~ # mongo --host /var/run/mongodb/mongodb-27017.sock -u admin -p aPassword --authenticationDatabase=admin --verbose
    MongoDB shell version v4.0.6
    connecting to: mongodb://%2Fvar%2Frun%2Fmongodb%2Fmongodb-27017.sock/?authSource=admin&gssapiServiceName=mongodb
    2019-02-23T09:34:08.025+0100 D NETWORK  [js] creating new connection to:/var/run/mongodb/mongodb-27017.sock
    2019-02-23T09:34:08.025+0100 D NETWORK  [js] connected to server /var/run/mongodb/mongodb-27017.sock
    2019-02-23T09:34:08.026+0100 D NETWORK  [js] connected connection!
    Implicit session: session { "id" : UUID("94094130-271c-4f5f-8b4a-c1ea435b0e7c") }
    MongoDB server version: 4.0.6
    >
    

    Thank you in advance for any ideas/guidance.

  • I was trying to do this, but failed 😞
    Seems like there is no way to make nodebb to listen to mongodb socket...

  • You can use a mongo uri instead of configuring all fields separately.

    See the docs for more info:

  • @PitaJ said in Mongo listening on unix socket ?:

    You can use a mongo uri instead of configuring all fields separately.

    See the docs for more info:

    Thank you for the suggestion, but unfortunately, I've already tried that and every time I use the uri para meter and I do not provide the "host" setting I get this error:

    2019-02-23T17:04:19.326Z [/var/run/nodebb/nodebb_0.sock/5781] - error: NodeBB could not connect to your Mongo database. Mongo returned the following error
    MongoParseError: No hostname or hostnames provided in connection string
    

    This is the config I am using, although I've tried many other combinations:

    "mongo": {
            "uri": "mongodb://myusername:[email protected]/var/run/mongodb/mongodb-27017.sock/dbname",
       }
    

    But, I guess this is a mongodb error not a nodebb one, so I'll try to figure it out.

    Thank you.

  • @fgallese that's odd. Maybe we have some logic mangling your uri. Have you tried it with the mongo cli client?

  • I finally figured it out... you need to put the path to the socket replacing the slashes with %2F.

    For example:

    "mongo": {
            "uri": "mongodb://username:[email protected]%2Fvar%2Frun%2Fmongodb%2Fmongodb-27017.sock/dbname"
        }
    

    Thank you for your help. Hope this post helps anybody who is facing the same issue.


Suggested Topics


| | | |