June 2014
Intermediate to advanced
696 pages
38h 52m
English
To help solidify the database operations, Listing 13.3 illustrates the full process of creating, listing, and deleting databases. A connection is made to the MongoDB server, and then lines 4–7 list the current databases. Then lines 8 and 9 create a new database by calling create-Collection(). Inside the createCollection() callback handler, the databases are listed again to verify creation.
Lines 15–32 delete the database by using dropDatabase(). Notice that inside the drop-Database() callback, a setTimeout() timer is implemented to wait for a number of seconds before checking the list of databases to verify that the database was deleted. The output is shown in Figure 13.3.
Listing 13.3 db_create_list_delete.js ...
Read now
Unlock full access