-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues connecting to Mongo Atlas #116
Comments
Getting the same error, it's not very clear how to connect to MongoDB Atlas. I've tried manually splitting the shard urls into a |
Same here. The API docs don't whisper a word about MongoDB Atlas. The user is left to wonder whether it should be done using the experimental Tls module, or by some other means. |
Okay everyone, here is how I finally succeeded: {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
import Database.MongoDB
import qualified Database.MongoDB.Transport.Tls as DbTLS
shard = "..." -- please note that you need to you use the reference to the * PRIMARY * shard in the target cluster, which often satisfies the following numbering pattern 'cluster0-shard-00-02.XXXXX.mongodb.net'
user = "..."
password = "..."
run_some_db_action = do -- the actual action you want to do
...
database_name = "..." -- the actual database against which the action should be registered
main = try (DbTLS.connect shard (PortNumber 27017)) >>= \case
Left e -> let e'= e :: SomeException in print ("Error while trying to connect: " ++ show e)
Right pipe -> do
isAuthorized <- access pipe UnconfirmedWrites "admin" $ auth user password -- "admin" is just used once for authentication; notice that 'UnconfirmedWrites' might not be required, I didn't survey all possible combinations of settings here;
if isAuthorized then access pipe master database_name run_some_db_action else throwIO $ userError "Failed to authenticate."
close pipe |
While this worked for a while, the primary shard changed, and now for some reason I can insert documents, but I always get zero documents back whenever I do a query. |
I actually managed to connect to the Atlas by using replicaSet <- Mongo.openReplicaSetTLS
( Text.pack "atlas-abcd123-shard-0"
, [ Mongo.host "something-shard-00-00.mfbis.mongodb.net"
, Mongo.host "something-shard-00-01.mfbis.mongodb.net"
, Mongo.host "something-shard-00-02.mfbis.mongodb.net"
]
)
pipe <- Mongo.primary replicaSet
authenticated <- Mongo.access pipe Mongo.master Mongo.admin (Mongo.auth mongoUser mongoPass However I still have this weird problem that queries continually return nothing. |
I'm trying to connect to Mongo Atlas but to no success. Getting the following error:
I've tried the suggestions from #84 but it seems like the issue is different.
This is how I connect:
Code is open source, rest can be found here.
On
Development
mode connecting to a local db it works fine (dbHostname: "127.0.0.1"
).But when trying to connect to Mongo Atlas, either by using
DBTLS.connect
orDB.connect
it does not work. Either by trying with the full connect URL provided by Mongo Atlas or only the hostAs error is from Network.BSD.getHostByName I'm not sure if issue should be opened here or not.
The text was updated successfully, but these errors were encountered: