I know using DBRefs is controversial. Regretfully, I’m not the DBA, so I can’t change its structure.
I have one collection called sensorsData
that stores documents generated by some devices, identified by their id:
idDevice: 2542
The value might change, there are tons of devices.
Regarding these documents, I’m only interested in those about broadcastings, identified by a concrete id, #3:
idSensor: 3
Other sensors do other stuff, one device might have different sensors.
Both fields are at level 0, after the id of the document itself:
{
"_id": {"$oid":"5f1957c7cdf25116937ed3ef"},
"idSensor":{"$numberLong":"3"},
"idDevice":{"$numberLong":"48"},
...
}
I need to filter all devices related to a concrete customer, identified by its specific id, #11. This id is referenced using a DBRef within a collection called devices
:
{
"_id": {"$numberLong":"2542"},
"group": {"$id":{"$numberLong":"11"}},
...
}
Notice this _id
is the idDevice
from the 1st collection.
groups
is the third collection, where the id of every customer originally lies:
{
"_id":{"$numberLong":"11"},
"name":"MyCustomerOfInterest",
...
}
I guess I don’t need to use this 3rd collection, the key information is stored within the 2nd one, that relates the customer to its devices.
So, the question:
How can I use devices
to filter the devices -or the documents with idSensor
#3- from sensorsData
that are related to this customer #11?
Thanks in advance.