0
{
"_id" : ObjectId("590b12b6330e1567acd29e69"),
"name": "Foo",
"sales_history" : [
{
"_id" : ObjectId("593ce8e4cfaa652df543d9e3"),
"sold_at" : ISODate("2017-06-11T06:53:24.881Z"),
"sold_to" : ObjectId("593509e938792e046ba14a02"),
"sold_products" : [
{
"product_dp" : 100,
"quantity" : 1,
"product_id" : ObjectId("591068be1f4c6c79a442a788"),
"_id" : ObjectId("593ce8e4cfaa652df543d9e5")
},
{
"product_dp" : 100,
"quantity" : 1,
"product_id" : ObjectId("593a33dccfaa652df543d924"),
"_id" : ObjectId("593ce8e4cfaa652df543d9e4")
}
]
},
{
"_id" : ObjectId("5944cb7142a04740357020b9"),
"sold_at" : ISODate("2017-06-17T06:25:53.332Z"),
"sold_to" : ObjectId("5927d4a59e58ba0c61066f3b"),
"sold_products" : [
{
"product_dp" : 500,
"quantity" : 1,
"price" : 5650,
"product_id" : ObjectId("593191ed53a2741dd9bffeb5"),
"_id" : ObjectId("5944cb7142a04740357020ba")
}
]
}
]
}
我有這樣的用戶模式。我需要product_id引用的詳細信息,並在sold_at日期字段中使用日期範圍搜索條件。
我預期的數據就像當我搜索在sold_at在以下:2017年6月11日
{ "_id" : ObjectId("590b12b6330e1567acd29e69"), "name": "Foo", "sales_history" : [ { "_id" : ObjectId("593ce8e4cfaa652df543d9e3"), "sold_at" : ISODate("2017-06-11T06:53:24.881Z"), "sold_to" : ObjectId("593509e938792e046ba14a02"), "sold_products" : [ { "product_dp" : 100, "quantity" : 1, "product_id": { _id:ObjectId("hsfgg123412yh3gy1u2g3"), name: "Product1", code: "FG0154" }, } ] } ] }
產品細節必須填充在PRODUCT_ID,SALES_HISTORY陣列需要在日期範圍過濾。