Creating Databases

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.

Image

Figure 12.5 Creating a new database in the MongoDB shell.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.103.59