Initializing the Application
Now that the application is done, you need to create the initial Customer
, Order
, and Product
documents in the database. There are several different ways to do this, such as using a database script or creating an admin interface for you application. To make it simple, this example includes a basic Node.js script to generate the data you’ve seen so far.
The code in Listing 28.30 shows a basic Node.js script that first cleans up, removing the customers, orders, and products collections. It then creates a Customer
document and an Order
document and then adds several Product
documents. It adds the Product
documents to the Customer
document’s cart and the Order
document’s items.
Get Node.js, MongoDB, and AngularJS Web 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.