5

I tried to connect my shiny app to mongodb server. I deployed app on shinyapps.io but got error again and again:

2019-10-22T18:14:14.694520+00:00 shinyapps[1117463]: Listening on http://127.0.0.1:36739
2019-10-22T18:14:36.665309+00:00 shinyapps[1117463]: Warning: Error in : No suitable servers found (`serverSelectionTryOnce` set): [socket timeout calling ismaster on 'seaport-shard-00-01-rysq4.gcp.mongodb.net:27017'] [socket timeout calling ismaster on 'seaport-shard-00-02-rysq4.gcp.mongodb.net:27017'] [socket timeout calling ismaster on 'seaport-shard-00-00-rysq4.gcp.mongodb.net:27017']
2019-10-22T18:14:36.670320+00:00 shinyapps[1117463]:   61: mongo_collection_command_simple
2019-10-22T18:14:36.670321+00:00 shinyapps[1117463]:   60: mongo
2019-10-22T18:14:36.670322+00:00 shinyapps[1117463]:   59: server [/srv/connect/apps/Seaport/app.R#223]
2019-10-22T18:14:36.670413+00:00 shinyapps[1117463]: Error : No suitable servers found (`serverSelectionTryOnce` set): [socket timeout calling ismaster on 'seaport-shard-00-01-rysq4.gcp.mongodb.net:27017'] [socket timeout calling ismaster on 'seaport-shard-00-02-rysq4.gcp.mongodb.net:27017'] [socket timeout calling ismaster on 'seaport-shard-00-00-rysq4.gcp.mongodb.net:27017']

More interesting what this app works great locally on my PC and moreover it worked fine on shinyapps last 2 weeks.

I tried to deploy app with standard connections string:

Data <- mongo(collection = 'Data',
              db = 'MaterialSeaport',
              url = 'mongodb+srv://<USER>:<PASSWORD>@seaport-rysq4.gcp.mongodb.net/test?retryWrites=true&w=majority')

With adding scram sha option:

Data <- mongo(collection = 'Data',
              db = 'MaterialSeaport',
              url = 'mongodb+srv://<USER>:<PASSWORD>@seaport-rysq4.gcp.mongodb.net/test?retryWrites=true&w=majority&authMechanism=SCRAM-SHA-1')

And with old connection string:

Data <- mongo(collection = 'Data',
              db = 'MaterialSeaport',
              url = 'mongodb://<USER>:<PASSWORD>@seaport-shard-00-00-rysq4.gcp.mongodb.net:27017,seaport-shard-00-01-rysq4.gcp.mongodb.net:27017,seaport-shard-00-02-rysq4.gcp.mongodb.net:27017/test?ssl=true&replicaSet=Seaport-shard-0&authSource=admin&retryWrites=true&w=majority')

How I can to connect my app with mongodb without this error?

Dynortice
  • 93
  • 7
  • I think shinyapps is having an issue on their end – Jordan Wrong Oct 23 '19 at 09:16
  • 1
    Did you resolve this? Having similar issues hosting an application that calls Atlas from a docker container. – dmanuge Aug 04 '20 at 22:43
  • Check your version of mongolite! I tried just about everything from SO and Github with this error before upgrading the mongolite version from 1.5 to 2.2.0 in my Dockerfile...apparently older versions of mongolite struggled connecting to Mongo clusters on Atlas. – dmanuge Aug 04 '20 at 23:25

1 Answers1

0

I was able to connect to MongoDB Atlas from shinyapps.io by whitelisting shinyapps.io IPs on MongoDB Atlas.

  1. Login to MongoDB Atlas
  2. Go to Network Access under the Security section of your project
  3. Click "Add IP Address", add the following shinyapp.io IPs:
  • 54.204.34.9
  • 54.204.36.75
  • 54.204.37.78
  • 34.203.76.245
  • 3.217.214.132
  • 34.197.152.155

These IP addresses can be found in [shinyapps.io Accessing Databases - Firewalls documentation][1]. The documentation has steps to whitelist on AWS, but the concept is the same.

Good luck!

agentcurry
  • 2,200
  • 3
  • 15
  • 20