Mongo に次のデータがあるとします。
{
"id": "foo1",
"description": "myFoo1",
"bars": [
{
"id": "foo1bar1",
"description": "myFoo1Bar1",
"builton": "2010-03-01T05:00:00.000Z"
},
{
"id": "foo1bar2",
"description": "myFoo1Bar2",
"builton": "2011-03-01T05:00:00.000Z"
}
]
}
{
"id": "foo2",
"description": "myFoo2",
"bars": [
{
"id": "foo2bar1",
"description": "myFoo2Bar1",
"builton": "2012-03-01T05:00:00.000Z"
},
{
"id": "foo2bar2",
"description": "myFoo2Bar2",
"builton": "2013-03-01T05:00:00.000Z"
}
]
}
私の質問は 2 つあります。
bar
指定した範囲内の日付を持つドキュメントのみを返し、bars
その日付範囲内ののみを返すクエリを実行することはできますか? たとえば、私の日付範囲が 2010-02-01 から 2010-04-01 であった場合、これは私が戻したいものです:
{
"id": "foo1",
"description": "myFoo1",
"bars": [
{
"id": "foo1bar1",
"description": "myFoo1Bar1",
"builton": "2010-03-01T05:00:00.000Z"
}
]
}
これはデータを構造化するための最良の方法ですか、それともより関係的に行う必要がありますか (つまり、2 つの別個のドキュメント (foos
とbars
) があり、fooId
フィールドがオンになっているだけbar
です)。