I know the include
-feature of RavenDB. It allows me to fetch a referenced document right away in one roundtrip to the database. But my problem is: The document i fetch in the first place is not including a reference to the "other" documents. But the "other" documents have references to the current document.
Imagine a setup where we have sites across the world. Each site
may trigger various alarms. Each alarm
has a reference to the site
via siteId
.
Now i would like to get a list of all the sites including all alarms. But it looks like, this is not possible with RavenDB? Since include
only accepts a "path" in the site
-Document which holds an id (or an array of ids) to the referenced document.
This could be solved by providing an array of alarmIds
within the site'-document and referencing this array in
include. But in contrast to a lot of examples featuring stuff like an
orderwith
lineItemswhere the order is a self contained thing, my
site` will be running for years, collecting alarms anywhere between 0 and a million. Which seems to be a bad idea to me.
Of course i could go the other way round: Query all alarms and include
the sites via sitesId
. But this would not return a site that has zero alarms.
So is this just a design error on my side? To i misunderstand something? Or is it just not possible to do this in one query and prevent a "n+1 query"?