How can I connect to an Atlas cluster with the SRV connection string format using ReactiveMongo? - mongodb

I have a play scala app and i have an atlas cluster which i am trying to connect. According to the ReactiveMongo this is possible. I can add my connection string gotten from Atlas to my app via
mongodb.uri
In my application.conf file. I have tried everything based on the instructions from reactivemongo and atlas db but i am still unable to connect to the cluster. using my mongoshell however, i am able to connect and have access to my db but it simply refuses to connect via my app.
Mongo simply returns an error "MongoError['No primary node is available! (Supervisor-13/Connection-14)']" } and logs a warning in my console Some options were ignored because they are not supported (yet): w, retryWrites. I am using scala version 2.12 and reactivemongo 0.12.6 with play 2.6.
My connection string is mongodb+srv://<username>:<password>#my-cluster.abo25.mongodb.net/my-db?retryWrites=true&w=majority
Any info or help would be greatly appreciated.

Solved my problem. It turns out the +srv string format works seamlessly from reactivemongo version 0.17 and i was initially on 0.16. After i upgraded (and also upgraded my code), i was able to connect to my cluster. I also found out one of the user credentials i was using was wrong so that plus the upgrade got me up and running.

Related

Authentication DB setting not working using mongoDB URI configuration

I am triyng to connect pyeve with a MongoDB Atlas replica set (https://cloud.mongodb.com/). I've connected successfully DB management tools from the same host, to make sure the deployment is working OK.
One particularity is that using Atlas, all users must authenticate against auth database, I cannot put my users in the application database, so I need to set authSource in MONGO_URI.
Now, when defining the MONGO_URI for the replica set, in settings.py, like this:
MONGO_URI = mongodb://<USER>:<PASS>#my-shard-00-00-tlati.mongodb.net:27017,my-shard-00-01-tlati.mongodb.net:27017,my-shard-00-02-tlati.mongodb.net:27017/<MY_DB>?ssl=true&replicaSet=my-shard-0&authSource=admin
The authSource=admin parameter seems to be ignored, (I've checked debugging pymongo's auth and the authentication source used is None).
MONGO_AUTH_SOURCE could be used to set the authorization database, but it has no effect since MONGO_URI is used in preference of the other configuration variables, according to eve's documentation.
Is this an issue or am I doing it wrong?
Found out that the problem was that I was using version 0.4.1 for flask-pymongo. Updating it to version 0.5.1 fixed the problem.

Spring REST MongoDB Starter Application queries

So I used the Spring MongoDB application starter kit from Github. I tried running the application and it ran great. All the functionality work great. I am confused how the connection for this is being established. Where does one specify the db userid, password and the db name? Coming from a MySQL background, though MongoDB isnt a mountain there are some differences that dont set clearly in the mind of newbies.
I followed the official documentation from here : https://spring.io/guides/gs/accessing-mongodb-data-rest/. Maybe can the above info be added to the docs?
You should read some docs on Springboot. Springboot is opinionated. That means it assumes lot of stuff and sets-up lot of things for you. For example, in your case, As soon as it sees mongo dependency in your pom. It will create a connection to mongodb with default values which are as follows
host: localhost
port: 27017
username:
password:
database: test
That is how it is working. But if you want it to be customized, even that is made easy by specifying in configuration files (application.properties or yaml). See the list of configuration properties that you can set
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

Mongo Spark connector with several hosts

I try to connect Spark to MongoDB using mongo-spark-connector_2.10-2.0.0 but it doesn't work when I have several hosts in the URI
My URI looks like that :
mongodb://login:password#cluster0-shard-0xxxxx:27017,cluster0-shard-0yyyyy:27017,cluster0-shard-0zzzzz:27017/database?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin
and I get errors like this
Command failed with error 8000: &apos;no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.&apos; on server cluster0-shard-0xxxxx
It works fine with other URIs that only have 1 host.
The problem was that I was using Atlas Free tier that requires SNI, which is not supported by the Mongo Java driver currently used by mongo-spark-connector_2.10-2.0.0.

[SailsJS / sails-mongo]SNI name

I'm trying to configure a MongoDB connection in SailsJS through sails-mongo, but no matter how I configure it, I'm getting this error.
MongoError: no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.
Could you assist me please?
The answer is in the error message. You are using a pre 3.4 driver. A v3.2 or v3.3 will not send the proper information to a v3.4 server instance.

Connect Gremlin shell to Titan Elasticsearch/Cassandra embedded instance?

I'm using Titan 0.3.2 in embedded mode with Cassandra and Elasticsearch. I am using the configuration documented in the titan docs for my cassandra-es.properties (fed into titan.sh/titan.bat):
storage.backend=embeddedcassandra
storage.cassandra-config-dir=config/cassandra.yaml
storage.index.search.backend=elasticsearch
storage.index.search.directory=/tmp/searchindex
storage.index.search.client-only=false
storage.index.search.local-mode=true
But I'm trying to get the right configuration for bin/cassandra-es.local to connect to the Titan server via the Gremlin client shell (with g = TitanFactory.open("cassandra-es.local") ). If I try to use the default version included with the download:
storage.backend=cassandrathrift
storage.hostname=127.0.0.1
The graph won't know anything about the ES index ("Index is unknown or not configured: search").
If I configure it with:
storage.backend=cassandrathrift
storage.hostname=127.0.0.1
storage.index.search.backend=elasticsearch
storage.index.search.client-only=false
storage.index.search.directory=/tmp/cassandra/elasticsearch
It will create an ES instance on another port that seems to exist separately from the one used by the server.
My question: (how) can I set up my Gremlin console to properly communicate with the Titan Embedded Server?
There was some recent discussion about this on the Google group. It looks like it's actually not possible to run two ES instances on one machine, so one of the easier ways around this is to set up ES separately on a VM.
I tried out this solution, and it works fine with these lines in both cassandra-es.local and titan-server-cassandra-es.properties:
storage.index.search.backend=elasticsearch
storage.index.search.hostname=<VM ES server IP>
storage.index.search.client-only=true
I can now access the same ES index from both the Gremlin shell and the Titan server.