Creating our collections
Now that we have created a database, let's populate it with some collections by performing the following steps:
- Run the following to create a collection for
Products
:> db.createCollection('Products')
MongoDB will respond with the following:
{ "ok" : 1 }
The preceding code indicates that the command was executed successfully. Note that the response is returned to us in the JSON format.
- Let's pause for a minute and break down the preceding command so that we understand what we just did:
- The
db
is a JavaScript object that represents the currently selected database. In our case, it isOrderBase
. - The
createCollection('Products')
function is one of the many member methods ofdb
. Needless to say, it creates a new collection and adds it todb
. Its parameter, a string, is the name of the new collection.
- The
In other words, working with MongoDB is actually a matter of issuing commands in pure JavaScript. Not only that, but the data itself...