Database IntegrationLesson 60Free preview
MongoDB Create DB
This lesson is part of Node.js · All levels
Summary
This lesson explains how to create and select MongoDB databases from Node.js with client.db(name). Keep in mind, the database in MongoDB is lazy: a new name is actually stored after a document has been written or a collection created. You also learn to check the database lists with the Databases command list.
Key points
- Client.db() without the argument using the default database of the connection string; with the argument select a specific name.
- A new database just pops up on the server after the data is written.
- Db.command({listDatabases: 1}) displays a list of databases (requires privileges).
- Writing to a database with the wrong name creates a new ghost database; make sure the name is consistent.
- The database name is limited to certain characters and is case-sensitive in some file systems.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.