简体   繁体   English

如何使用 Nodejs 部署 Mongodb 数据库

[英]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.

相关问题 您现在如何使用 Zeit 部署 Nodejs? - How do you deploy Nodejs using Zeit now? 使用 Kubernetes 部署 Mongodb 和 NodeJS - Deploy Mongodb and NodeJS with Kubernetes 如何将regex应用于数据库中的值以在mongodb中进行查询? - How do you apply regex to value in database to query against in mongodb? 如何使用 GCP 的 NodeJS 库部署新的 API 网关 OpenAPI 规范? - How do you use GCP's NodeJS library to deploy new API Gateway OpenAPI Specs? 如何在nodeJS和mongoDB中进行聚合 - How to do aggregation in nodeJS and mongoDB 如何将NodeJS项目部署为API - How do I deploy a NodeJS project as an API 如何将多个参数从客户端通过NodeJS传递给MongoDB? - How do you pass multiple parameters from the client through NodeJS to MongoDB? 如何将 Google App Engine NodeJS 应用程序连接到 Compute Engine 中的 MongoDB? - How do you connect Google App Engine NodeJS app to MongoDB in Compute Engine? 如何使用Node.js脚本部署mongodb副本集(副本集部署的自动化) - how to deploy a mongodb replicaset using nodejs script(Automation of replicaset deployment) NodeJs 没有在 MongoDb 中创建数据库? 如何解决? - NodeJs is not creating a database in MongoDb? How to solve it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM