MongoDB Connection

For MongoDB, it says here https://www.astronomer.io/guides/connections/ to connect to MongoDB:

Despite this, we’ve had no luck creating a mongo connection that works with MongoHook. We are using MongoDB Atlas and our URI looks something like mongodb+srv://myuser:mypassword@my-cluster.dwxnd.gcp.mongodb.net/mydb?retryWrites=true&w=majority

How can we then split up the URI into a JSON object of connection options? Or should we be using the Login and Password fields in the UI? Have been struggling with this for a while so any help is appreciated!

Hey @nick!

So you’re going to want to split that Connection String URI into separate fields per MongoDB’s reference guide. They give some great examples in that doc, but it looks like, for your case, this would look like the following:

  • Host: my-cluster.dwxnd.gcp.gcp.mongodb.net/mydb
  • Schema: N/A
  • Login: myuser
  • Password: mypassword
  • Port: Hm, looks like there’s no port in your connection string- it should be after your host name. Is that something you can track down in the Atlas UI?

I’d definitely give the doc a read, but the above is a rough estimate. Let me know what you find!

2 Likes

Yeah this worked. I was thrown off a bit by the MongoDB section in the astronomer connections guide, which made it seem like I should leave those fields blank. Appreciate the response on this.