[英]How do you deploy a Mongodb database with Nodejs
I have a working web app with MongoDB
database.我有一个工作 web 应用程序和
MongoDB
数据库。 My app is making fetching/posting info onto the database running on a localhost我的应用程序正在获取/发布信息到在本地主机上运行的数据库
const db = monk('localhost/datbaseName') //create/connect to database 'databaseName'
const posts = db.get('posts') //created a collection named 'posts' in 'databaseName'
I recently setup a database Cluster
on mongoDB Atlas
.我最近在
mongoDB Atlas
上设置了一个数据库Cluster
。 Is there a way to now connect my code to the Atlas cluster
database, instead of using localhost/datbaseName
?现在有没有办法将我的代码连接到
Atlas cluster
数据库,而不是使用localhost/datbaseName
?
I don't know much about using MongoDB Atlas but a very simple way of deploying your mongo database is to use mlab.我对使用 MongoDB Atlas 了解不多,但部署 mongo 数据库的一种非常简单的方法是使用 mlab。 You can check them out at https://mlab.com
您可以在https://mlab.com查看它们
after logging in to your mlab account click on "create new" select amazon web services as your cloud provider and also select a free sandbox then hit continue pick us virginia east and hit continue give the database a name and then submit your order登录到您的 mlab 帐户后,单击“创建新”select 亚马逊 web 服务作为您的云提供商以及 select 一个免费的美国沙箱然后点击一个名称然后提交您的弗吉尼亚东部
once you have completed all that click on the database you just created click on the users tab and add a database user.完成所有操作后,单击刚刚创建的数据库,单击用户选项卡并添加数据库用户。 over here provide a username and password for the database.
在这里提供数据库的用户名和密码。 you will need this in setting up your mongo connection.
您在设置 mongo 连接时将需要它。
after that is complete you can then copy the mongouri shown and replace the relevant fields with your username and password完成后,您可以复制显示的 mongouri 并将相关字段替换为您的用户名和密码
replace 'localhost/datbaseName' with mongodb+srv://username:password@cluster0-1eyxe.mongodb.net/datbasename?retryWrites=true&w=majority用 mongodb+srv://username:password@cluster0-1eyxe.mongodb.net/datbasename?retryWrites=true&w=majority 替换 'localhost/datbaseName'
it will connect you with atlas cluster.它会将您与 atlas 集群连接起来。
You are directed to mongodb atlas because mlab has been acquired by mongodb only.您将被定向到 mongodb 地图集,因为 mlab 仅由 mongodb 获得。 I would suggest you to create a cluster on mongodb atlas.
我建议您在 mongodb 地图集上创建一个集群。 You can signup for a free M0 cluster from https://www.mongodb.com/cloud/atlas/
您可以从https://www.mongodb.com/cloud/atlas/注册免费的 M0 集群
Sign up and then click on create cluster.注册,然后单击创建集群。
You can refer to documentation for creating a new cluster here: https://docs.atlas.mongodb.com/tutorial/create-new-cluster/index.html您可以在此处参考创建新集群的文档: https://docs.atlas.mongodb.com/tutorial/create-new-cluster/index.html
and let me know in case you need more help in setting up the cluster如果您在设置集群时需要更多帮助,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.