[Solved] Mongo_URL error: cannot read property 'split' of null

Hi All,
I’d greatly appreciate some help. I’m having difficulty connecting my development meteor instance to a remote mongodb atlas server. I am running version 1.8.1 as have just updated because I also couldn’t get it to work on version 1.5.1

The issue only arises when I try to set the MONGO_URL parameter (app loads fine when connecting to local minimongo instance)

I have no problem connecting via mongodb compass from the same machine so theoretically its nothing to do with whitelisting etc.

I’m using a batch file in windows and here is the contents (this has been copied from atlas’s “connect your application”>“connection string only”

SET MONGO_URL="mongodb+srv://[myusername]:[mypassword]@cluster0-u8ed4.gcp.mongodb.net/test?retryWrites=true^&w=majority"
meteor

The error I am getting is as follows:

TypeError: Cannot read property 'split' of null
W20191024-21:32:14.879(13)? (STDERR)     at parseSrvConnectionString (C:\Users\Alex\AppData\Local\.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb-core\lib\uri_parser.js:40:23)
W20191024-21:32:14.880(13)? (STDERR)     at parseConnectionString (C:\Users\Alex\AppData\Local\.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb-core\lib\uri_parser.js:421:12)
W20191024-21:32:14.881(13)? (STDERR)     at connect (C:\Users\Alex\AppData\Local\.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb\lib\operations\mongo_client_ops.js:188:3)
W20191024-21:32:14.882(13)? (STDERR)     at connectOp (C:\Users\Alex\AppData\Local\.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb\lib\operations\mongo_client_ops.js:292:3)
W20191024-21:32:14.884(13)? (STDERR)     at executeOperation (C:\Users\Alex\AppData\Local\.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb\lib\utils.js:420:24)
W20191024-21:32:14.885(13)? (STDERR)     at MongoClient.connect (C:\Users\Alex\AppData\Local\.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb\lib\mongo_client.js:168:10)
W20191024-21:32:14.885(13)? (STDERR)     at Function.MongoClient.connect (C:\Users\Alex\AppData\Local\.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb\lib\mongo_client.js:372:22)
W20191024-21:32:14.886(13)? (STDERR)     at new MongoConnection (packages/mongo/mongo_driver.js:177:11)
W20191024-21:32:14.887(13)? (STDERR)     at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
W20191024-21:32:14.888(13)? (STDERR)     at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:10)
W20191024-21:32:14.889(13)? (STDERR)     at Object.defaultRemoteCollectionDriver (packages\underscore.js:784:19)
W20191024-21:32:14.890(13)? (STDERR)     at new Collection (packages/mongo/collection.js:97:40)
W20191024-21:32:14.890(13)? (STDERR)     at new AccountsCommon (packages/accounts-base/accounts_common.js:23:18)
W20191024-21:32:14.891(13)? (STDERR)     at new AccountsServer (packages/accounts-base/accounts_server.js:23:5)
W20191024-21:32:14.892(13)? (STDERR)     at server_main.js (packages/accounts-base/server_main.js:7:12)
W20191024-21:32:14.895(13)? (STDERR)     at fileEvaluate (packages\modules-runtime.js:336:7)

Can someone tell me what I am doing wrong?

1 Like

I’m still struggling with this.

After looking at the operation of meteor’s parseSrvConnectionString function in the meteor application files it looks like the URL.parse function cannot recover the hostname when this mongoURL is parsed into it. The first part of this function is replicated below

function parseSrvConnectionString(uri, options, callback) {
  const result = URL.parse(uri, true);
  if (result.hostname.split('.').length < 3) {
    return callback(new MongoParseError('URI does not have hostname, domain name and tld'));
  }

Its the result.hostname property that is coming up as empty after the URL.parse.

If I rewrite it to parse the mongo URL without the “mongodb+srv” in front of it (i.e. by editing the mongo_url, or by having it parse a subset of the URL i.e. uri.substring(15,uri.length)) the hostname does get resolved although other parts of it seem to get missed so that when it gets packaged back up as the finalstring at the bottom of the function it doesn’t look complete.

I’m sure this default meteor code all works and I shouldn’t have to edit base meteor code to get through this validation… so presumably my Mongo_URL must be wrong. Any ideas?

Issue resolved. I removed the double quotes in the mongo url in the batch file… too used to assuming strings need to be denoted by some sort of quote marker. Thanks!

3 Likes

One of the perfect solution…with the same steps it resolved my problm