Currently, I am in the process of redesigning a MongoDB database structure where the reviews for a specific product will be integrated into the product document itself, rather than maintaining separate collections for products and reviews. I have created a loop that goes through each review and inserts it into the corresponding product document. However, upon querying the database later on, I have noticed that if a product has multiple reviews, the first review is duplicated for each review present.
Any assistance or guidance on this matter would be greatly appreciated.
Here are examples of the product and review documents prior to the update:
// Product Document
{
"_id" : ObjectId("5d0b6d1cd7367de7f58b4a77"),
"p2507945_asin" : "B00005JHK9",
...
}
// Review Documents for Product
{
"_id" : ObjectId("5d0b70f2d7367de7f5fa1da3"),
...
}
...
Snippet of the code used for the update:
var RvColcursor = db.p250794_reviews.find({}, {_id : 0});
...
An example of the returned output:
{
"_id" : ObjectId("5d0b6d1cd7367de7f58b4a77"),
"p2507945_asin" : "B00005JHK9",
...
}