Book Image

Learning Node.js for Mobile Application Development

Book Image

Learning Node.js for Mobile Application Development

Overview of this book

Table of Contents (21 chapters)
Learning Node.js for Mobile Application Development
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
14
Creating an E-Commerce Application Using the Ionic Framework
Index

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 adds it to db. Its parameter, a string, is the name of the new collection.

In other words, working with MongoDB is actually a matter of issuing commands in pure JavaScript. Not only that, but the data itself and the responses to the commands are encoded...