Mongodb API で Azure cosmos db を使用しています。また、私はマングースを使用してスキーマを作成し、データベースに新しいドキュメントを作成しています。Node.jsも使用しています。
この時点で、埋め込みドキュメントで一対多の関係を使用することを検討しています。
データ構造は次のようになります。
{
"_id" : "locality1",
"_type" : "Locality",
"name" : "Wallmart",
"subsectionList" : [
{
"_id" : "subsection1",
"_type" : "SubSection",
"name" : "First floor",
"sensorList" : [
{
"_id" : "sensor1",
"_type" : "Sensor",
"placement" : "In the hallway"
},
{
"_id" : "sensor2",
"_type" : "Sensor",
"placement" : "In the ceiling"
}
]
},
{
"_id" : "subsection2",
"_type" : "SubSection",
"name" : "Second floor",
"sensorList" : [ ],
}
],
}
親からは何も取得せず、「sensor1」オブジェクトのみを取得したい。
クエリを使用すると、「locality1」オブジェクト全体と、その下にあるすべてのサブセクションとセンサーのみを取得できます。不必要に大量のデータである大規模な場合。
これまでの私のクエリは次のとおりです。
Locality.find().where('subsectionList.sensorList._id').equals("sensor1").then(doc => {
console.log(doc)
})
ヒントをいただければ幸いです。:)