简体   繁体   English

如何确认是否已为MongoDB for ReactJS + NodeJS Express创建数据库?

[英]How to confirm if database has been created for MongoDB for ReactJS + NodeJS Express?

I am following a tutorial and got the following set up: 我正在学习教程,并进行了以下设置:

MongoClient.connect('mongodb://localhost/newdatabase', function(err, dbConnection) {
  db = dbConnection;
  var server = app.listen(3000, function() {
      var port = server.address().port;
      console.log("Started server at port", port);
  });
});

Just by defining the URL with the name of the database, does the database get created? 仅通过使用数据库名称定义URL,就可以创建数据库吗? Or would I have to go on the terminal and manually create it? 还是我必须在终端上手动创建它? How can I check if /newdatabase has been created? 如何检查/newdatabase是否已创建?

Also, how can I access the URL on the browser? 另外,如何在浏览器中访问URL? Why aren't they defining the port number after the //localhost ? 他们为什么不在//localhost之后定义端口号?

Thank you! 谢谢!

MongoDB will create the database on the fly, as soon as you interact with it -- try adding a collection / document to it. 与您进行交互后,MongoDB会即时创建数据库-尝试向其中添加集合/文档。

As for the port, it's probably using the default port ( 27017 ) since you aren't providing one. 至于端口,它可能正在使用默认端口( 27017 ),因为您没有提供端口。 You wouldn't typically connect to mongo through your browser, though. 不过,您通常不会通过浏览器连接到mongo。 Attempting that results in this message: 尝试生成此消息:

It looks like you are trying to access MongoDB over HTTP on the native driver port.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NodeJS:更新或创建MongoDB文档后发送响应 - NodeJS: Send Response after MongoDB Document has been updated or created NodeJS + Express + Mongoose(MongoDB)数据库插入错误 - NodeJS + Express + Mongoose(MongoDB) Database Insert Error 创建后使用数据库对象 - Use database object after it has been created 使用 NodeJS 后端(使用 express)为 heroku 上的服务器/数据库部署 ReactJS 应用程序 - Deploying ReactJS app with NodeJS backend (using express) for server/database on heroku 如何检测该页面已被Reactjs重新加载? - How to detect that page has been reloaded Reactjs? 我一直在我的新 ReactJs NodeJs 项目中测试 MySql 连接,但没有任何内容插入到我的数据库中。 我的代码有问题吗 - I've been testing MySql connection in my new ReactJs NodeJs project but nothing has been inserted into my database. Is there any problem with my code 如何为每个注册的用户创建单独的数据库:Nodejs、express、mongodb 和 mongoose - How to create seperate database for every user who register : Nodejs , express, mongodb & mongoose Node.js + Express:将某些内容插入数据库后,如何更新页面? - Node.js + Express: How to update page when something has been inserted into database? nodejs如何控制已经打开的浏览器 - How to control the browser that has been opened by nodejs 无法使用MongoDB NodeJS Express从视图访问数据库 - Can't access database from views using MongoDB NodeJS Express
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM