Configure Your MongoDB Connection
Specify target database in connection string
When connecting to an Atlas cluster, you must specify the database that you want to interact with as the default database in your connection string. You must add the database name to your connection string after the hostname.
The following example specifies the sample_restaurants
target database
in a sample connection string:
mongodb+srv://user0:pass123@mongo0.example.com/sample_restaurants
Specify connection in mongoid.yml
At the root level of your project, create a config
directory.
Then, create a file in this directory called mongoid.yml
.
Paste the following configuration into the mongoid.yml
file,
making sure to replace the <connection string>
placeholder
with your connection string that references the target database:
development: clients: default: uri: <connection string>
After completing these steps, your Sinatra web application is ready to connect to MongoDB.
Note
If you run into issues, ask for help in the MongoDB Community Forums or submit feedback by using the Feedback button in the upper right corner of the page.