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