连接Atlas 集群时,必须在连接字符串中将要与之交互的数据库指定为默认数据库。 您必须将数据库名称添加到连接字符串中的主机名之后。
以下示例在示例连接字符串中指定了 sample_restaurants 目标数据库:
sample_restaurants
mongodb+srv://user0:pass123@mongo0.example.com/sample_restaurants
在项目的根级别,创建一个 config目录。 然后,在此目录中创建一个名为 mongoid.yml 的文件。
config
mongoid.yml
将以下配置粘贴到 mongoid.yml文件中,确保将 <connection string> 占位符替换为引用目标数据库的连接字符串:
<connection string>
development: clients: default: uri: <connection string>
完成这些步骤后,您的 Sinatra Web应用程序就可以连接到MongoDB 了。
如果您运行问题,请在 MongoDB Community论坛中寻求帮助,或使用页面右上角的 Feedback按钮提交反馈。
后退
创建连接字符串 - Sinatra
来年
查看MongoDB数据 - Sinatra