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