13

I am trying to connect to a database that I have hosted at MLab. I am using the StrongLoop API. I've placed the config information for my hosted databases into my datasources.json and config.json files, but whenever I run the directory with npm start, I get throw new Error ('double colon in host identifier';) at api\node_modules\mongodb\lib\url_parser.js:45.

I have also made sure to install the loopback-connecter-mongodb npm package.

Here is a snippet of datasources.json (without the actual database details, of course):

{
  "db": {
    "name": "db",
    "connector": "mongodb",
    "host": "ds047355.mlab.com",
    "database": "dbtest",
    "username": "user",
    "password": "fakepassword",
    "port": 47355
  }
}

Here is the config.json file:

{
  "restApiRoot": "/api",
  "host": "ds047355.mlab.com",
  "port": 47355,
  "remoting": {
    "context": {
      "enableHttpContext": false
    },
    "rest": {
      "normalizeHttpPath": false,
      "xml": false
    },
    "json": {
      "strict": false,
      "limit": "100kb"
    },
    "urlencoded": {
      "extended": true,
      "limit": "100kb"
    },
    "cors": false,
    "errorHandler": {
      "disableStackTrace": false
    }
  },
  "legacyExplorer": false
}

Got any ideas?

sleepy_daze
  • 415
  • 1
  • 6
  • 19
  • 2
    You have the host and the port inside the `config.json` as the data source ones, and this is not their place. the config should include the Host and Port of where you want loopback to run the node server, which locally could be `0.0.0.0:3000` – Rabea Mar 24 '16 at 20:34
  • Thanks for your help Rabee! I added the host as `0.0.0.0` in `config.json` and added the port as `3000`, but I still get the same error... – sleepy_daze Mar 25 '16 at 00:13
  • It also may be when you use `:` or `/` in your mongodb password – Raj Adroit Aug 03 '16 at 08:47

5 Answers5

7

I finally solved my problem resulting in this error. It was reading one of my server URLs as http://0.0.0.0/:8080 but was fixed when I changed to http://0.0.0.0:8080

Hope this helps you or someone else.

objectively C
  • 732
  • 6
  • 23
2

It generally happens when you provide wrong information about your URL. In my case, i provided the url.com/db_name instead of url.com

Abdellah Alaoui
  • 4,276
  • 1
  • 22
  • 33
2

I HAVE THE SOLUTION!

During my times with self hosting on Ubuntu, I was unable to load my settings.json. For some reason, I had to remove all white space out of it.

So I finally move over to Meteor Galaxy, follow their tutorial to the letter, and get all sorts of mongo errors. So what the heck, lets remove all the white space, right?

tldr; Put your entire setting.json on one line

check www.skyrooms.io to see running :D

Andy
  • 868
  • 10
  • 16
2

Make sure you don't have weird characters in it (e.g. @#$%^:,/.), I had some and got that error message. Changed the password to an alphanumeric one and works flawlessly.

aluxian
  • 928
  • 10
  • 26
1

I got the same error and finally solve it. My previuos datasource json :

"db": {
   "host": "mongodb://127.0.0.1",
   "port": 27017,
   "url": "",
   "database": "dbname",
   "password": "12345",
   "name": "db",
   "user": "admin",
   "connector": "mongodb"
}

Then, i filled the url value like this :

"db": {
   "host": "mongodb://127.0.0.1",
   "port": 27017,
   "url": "mongodb://127.0.0.1:27017/dbname",
   "database": "dbname",
   "password": "12345",
   "name": "db",
   "user": "admin",
   "connector": "mongodb"
}