Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
Last active February 13, 2019 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgadiraju/0320e996bfc563c9e0b4258db5bd40ea to your computer and use it in GitHub Desktop.
Save dgadiraju/0320e996bfc563c9e0b4258db5bd40ea to your computer and use it in GitHub Desktop.
const mongoConnection = Mongo()
const retail = mongoConnection.getDB("retail")
const orders = retail.orders
const orderItems = retail.orderItems
orders.find().forEach((order) => {
let orderDetails = order
let orderItemDetails = []
orderItems.
find({"order_item_order_id" : order.order_id}).
forEach((orderItem) => {
orderItemDetails.push(orderItem)
})
if(orderItemDetails.length != 0)
orderDetails['order_item_details'] = orderItemDetails
retail.orderDetails.insertOne(orderDetails)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment