I'm building an app where users can upload records of many different types. For example, videos, images, stories.
It seems to me that the best thing to do when designing my arango datebase, is to have one collection for videos, one for images, and one for stories.
The problem comes when trying to get a list of all records. There is a view in the app that a user can see on their dashboard, that contains a table, that lists the first 20 of their records that they have created (a mixture of videos, images, stories), in order of most recently created first.
I've been through the arangojs documentation but I am still not quite sure what the best way is to model this, so that I can write a performant query.
The best thing I can think of, is to just have a jagged records collection that contains all videos, images, and stories. But this does not seem right, as the record types are not really similar enough to be considered the same thing. And the logic of the database, where we previously had one collection per record type, will be compromised for the sake of writing this one query.
Doing some research, someone has suggested, as an alternative, doing a union on several whole tables, as follows, but surely this is not very good for performance?
return union (
for x in collection1
return x,
for y in collection2
return y
)
(Source: https://github.com/arangodb/arangodb/issues/8711)
Another option, is to do what I'd do if it was a SQL database, and have a parent table and "subclass" tables, but this is quite cumbersome and I'd rather avoid it if there is a better way with Arango.
For example:
Records: _key, createdByUserId, title, createdAt
Videos: _key, recordKey, duration
Images: _key, recordKey, width, height
Stories: _key, recordKey, bodyText
Then, with that, some kind of join.
The third option I can think of is to use an edge collection. But I am conflicted about this also. The reason for this is that a image record, for example, only has one creator, so it seems to me that the database will be better normalised if the creatorId property exists as an attribute of the image or video record itself.
Advice would be greatly appreciated, as I am unsure which option to commit to.