MongoImport Error: cannot unmarshal DNS message

As part of the MongoDB World Hackathon, I’m trying to import more data into my cluster and I’m now experiencing this error which I didn’t have the first time I ran this import script

This issue is very similar to an earlier one but I’m having difficulty applying the solution there.

Perhaps more newbie-friendly instructions as to what I should do will help because I saw instructions concerning changing host name or port to replica set something, but I didn’t quite what exactly to do.

@Mark_Smith @nraboy

Tagging the people from the similar issue incase they can help out: @Kushagra_Kesav @Ramachandra_Tummala @Joshua_Cadavez

System details are:
Ubuntu 20.04.4 LTS
Python 3.10.4
MongoDB shell version v5.0.8

mongo --version:
Build Info: {
    "version": "5.0.8",
    "gitVersion": "c87e1c23421bf79614baf500fda6622bd90f674e",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
1 Like

May be your network not supporting srv type string
Try longform of string(old style)
If you have Atlas account you can get full mongoimport command from command line tools
You may get sample command from our forum threads too

@Mark_Smith this might be a problem with the & in your script?

Just looking into this - hopefully I’ll have a fix shortly.

Hi @Fiewor_John - have you modified at all? I can only reproduce your error if I put double quotes around the $* at the end of that script, so it looks like "$*".

I previously modified it in an attempt to add --host and --port but I have removed those flags.

Here’s what it looks like when I open it up in vim

Thanks @Fiewor_John - I’ve just realised that I confused your error message with another :man_facepalming:

I agree with @Ramachandra_Tummala that this may be a limitation of your DNS server. Have you changed network since the last time things worked?

If the mongodb+srv URI doesn’t work, there is an alternative. I think the following should work for you (remember to put your password in the correct place :slightly_smiling_face: )


Incidentally, if the connection string works for you, then you have @Joe_Drumgoole to thank for the following blog post that taught me how to do this :slight_smile:: MongoDB 3.6: Here to SRV you with easier replica set connections | MongoDB Blog

I’m getting a

After last host:port in your connect string add / before ?


I think you’re right. I missed a / :man_facepalming:


Don’t forget to put your database name in, either - requires it.

1 Like

Thanks Mark and @Ramachandra_Tummala . I actually tried this already after I observed that @Joe_Drumgoole had a /test in his blog post but it gave another weird error which I frankly didn’t want to bother anyone with again :sleepy:

But I’ll share it here and try again later cause I fear it has something to do with my network

I’m starting to think the network you’re on is quite restricted. Can you try pinging one of the nodes, like this


If you get something like the following then you might be able to access the replica-set:

64 bytes from icmp_seq=0 ttl=50 time=29.413 ms
64 bytes from icmp_seq=1 ttl=50 time=29.855 ms
64 bytes from icmp_seq=2 ttl=50 time=29.782 ms
64 bytes from icmp_seq=3 ttl=50 time=29.692 ms

If you can, then try using mongosh directly to connect to the replicaset using your SRV connection string, and then the comma-separated connection string, and see what the results are.

If the ping times out then there’s a good chance you just can’t connect to MongoDB Atlas over the network you’re on.

I just tried these and I’m able to both ping one of the nodes and connect to the SRV string using mongosh

However, connecting to the comma-separated connection string gives this:

1 Like

:grimacing: Okay! I think it’s starting to look like @Joe_Drumgoole was right when we were talking about this issue this morning - I think there’s a bug in the script, but I can’t work out how to fix it exactly. Please change the last block of the script so it looks like the following, and paste in your connection string:

cat *.export.CSV | mongoimport \
    --collection=eventscsv \
    --mode=upsert \
    --writeConcern '{w:1}' \
    --type=tsv \
    --columnsHaveTypes \
    --fieldFile="${fieldfile}" \
    --uri 'PUT_YOUR_URI_HERE'

You can now run it without the --uri flag - don’t forget to add your database name at the end - I can see you’re not in the first screenshot above :wink:

Let me know how this goes! :crossed_fingers:

1 Like

I’ve fixed it!

After taking a closer look at the blog post you shared, I added ssl=true to the comma-seperated connection string and it finally worked!

So. here’s the final connection string that worked:

And the link to the doc explaining the ssl part of mongoDB URI for anyone that might come across this later:

Thanks @Ramachandra_Tummala @Mark_Smith @Joe_Drumgoole


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