How to connect with mongodb+srv from pyspark?

I am trying to connect mongo db from pyspark . My url starts with mongodb+srv , though it is throwing an error
java.lang.IllegalArgumentException: requirement failed: Invalid uri: 'mongodb+srv

I have used below jar files:
bson-3.4.2 , mongo-java-driver-3.4.2, mongodb-driver-core-3.4.2

1 Like

I’m having the same issue, did you solve it?

If you get the same error, that is

You have to set the URI correctly. If you are unsure how to do it, share the URI you are using so that we could help.

Which version of the spark connector are you using?

FWIW, we released a new version 10.0 Maven Central Repository Search.

Announcement is here Introducing the Newest Version of the MongoDB Spark Connector | MongoDB Blog

Your URU should resemble the something like , "spark.mongodb.connection.uri","mongodb+srv:// USERNAME:PASSWORD@xxxxxxo.mongodb.net/somedatabasename?retryWrites=true&w=majority"

I am using spark - 2.4.3 , also can you please provide one sample code with the connector you have mentioned in the post here for reading data from mongodb using pyspark . where connection for mongodb is with srv .

thanks

my URL exactly resembles like this and I had tried to read data using pymongo and it had worked with same url . URL is not incorrect .

not yet !! for work around i have used pymongo lib , but not in spark …i am exploring the option with spark .

URL is correct …I have used pymongo python lib and able to pull the data from mongodb . but with spark issue is coming and it is due to mainly mongodb + srv . I need correct jar and one sample code for data read from mongodb using spark .