I am a relatively new to using the populate feature in Mongoose. I have the need to populate the "_id" field of my "Customer" model with the list of Orders made by this customer. Here are the Schemas.
Customer_Schema = {
name : string,
phone : string,
email : string
Orders_Schema= {
customerID : string, // This is the object ID of the customer from the "Customer_Schema"
phone : string,
email : string
Now I would like to know how to setup the "refs" in the Schemas and how to execute the populate command. For my end result I would like to get the Customer with all the order data under their "customerID".
Thanks.
You can set up a reference in the orderSchema that points to the "Customer" model.
Now you can use populate to get customer along with orders,