MongoDB doesn’t provide a command in the shell to explicitly create databases. Instead, you can simply use use <new_database_name>
to create a new database handle. Keep in mind that the new database will not actually be saved until you add a collection to it. For example, the following commands create a new database named newDB
and then add a collection named newCollection
to it:
use newDB
db.createCollection("newCollection")
To verify that the new database exists, you can then use show dbs
, as shown in Figure 12.5.