i have a document in mongodb like this:
db.full_stock_order_flow.find({skuId:"a19011100abc0084",stockGroup:"ABC_01"})
result:
{
"_id" : ObjectId("59bb5698c37fe6085b36f7d5"),
"skuId" : "a19011100abc0084",
"stockGroup" : "ABC_01",
"orderflowJsonEncode" : [
{
"calcDate" : "2016-01-28",
"acbQty" : NumberInt(0),
"abcQty" : NumberInt(30),
"stockQty" : NumberInt(0),
"isActiveDay" : true,
"outQtyWhenFullStockQty" : NumberInt(30)
},
{
"calcDate" : "2016-01-29",
"acbQty" : NumberInt(0),
"abcQty" : NumberInt(13),
"stockQty" : NumberInt(53),
"isActiveDay" : true,
"outQtyWhenFullStockQty" : NumberInt(13)
}
],
"createdOn" : "2017-09-05 12:27:04",
"createdBy" : "helloworld"
}
and i want to find the sub document and insert it the other collectin with parent Document like change 2 document without sub document in the other document:
{
"_id" : ObjectId("59bb5698c37kk6085b36f7d5"),
"skuId" : "a19011100abc0084",
"stockGroup" : "ABC_01",
"calcDate" : "2016-01-28",
"acbQty" : NumberInt(0),
"abcQty" : NumberInt(30),
"stockQty" : NumberInt(0),
"isActiveDay" : true,
"outQtyWhenFullStockQty" : NumberInt(30),
"createdOn" : "2017-09-05 12:27:04",
"createdBy" : "helloworld"
}
{
"_id" : ObjectId("59bb5698c37kk6085b36f7d5"),
"skuId" : "a19011100abc0084",
"stockGroup" : "ABC_01",
"calcDate" : "2016-01-29",
"acbQty" : NumberInt(0),
"abcQty" : NumberInt(13),
"stockQty" : NumberInt(53),
"isActiveDay" : true,
"outQtyWhenFullStockQty" : NumberInt(13),
"createdOn" : "2017-09-05 12:27:04",
"createdBy" : "helloworld"
}
what can i do? i use this :
var record=db.full_stock_order_flow.find({skuId:"a19011100abc0084",stockGroup:"US_01"});
var arr=record.orderflowJsonEncode;
arr.forEach(
function(item){
db.tt123.insert({"skuId": record.skuId,"stockGroup": record.stockGroup , "orderflowJsonEncode":item});
}
)