MongoDB-idiomatic way to have an array of DBRefs to DIFFERENT types

  Kiến thức lập trình

So we currently have a collection that has an array of DBRef(x, ObjectId). The array has the meaning of “children”. The point is that x is ambiguous, so our collection can have children that sit in various collections.

Denormalizing is certainly an option but the children really also live much on their own and deserve their own collections, so I would rather keep them separate.

Now, DBRefs are apparently evil/inefficient for some reason (I could not find out why, though, details here would also be appreciated).

Now the main question: How would you refactor this (if not denormalizing)? Say x can be vegetable or fruit or meat. Should we then change the children array to multiple arrays:
vegetables, fruits, meats each being a flat array of ObjectIds? Or what would be the normal idiomatic way?

LEAVE A COMMENT