Creating our collections

Now that we have created a database, let's populate it with some collections by performing the following steps:

  1. 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.

  2. 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 is OrderBase.
    • The createCollection('Products') function is one of the many member methods of db. Needless to say, it creates a new collection and ...

Get Learning Node.js for Mobile Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.