Jo Ko
Jo Ko

Reputation: 7575

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? Or would I have to go on the terminal and manually create it? How can I check if /newdatabase has been created?

Also, how can I access the URL on the browser? Why aren't they defining the port number after the //localhost?

Thank you!

Upvotes: 1

Views: 133

Answers (1)

dvlsg
dvlsg

Reputation: 5538

MongoDB will create the database on the fly, as soon as you interact with it -- try adding a collection / document to it.

As for the port, it's probably using the default port (27017) since you aren't providing one. You wouldn't typically connect to mongo through your browser, though. Attempting that results in this message:

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

Upvotes: 2

Related Questions