MongoDB – is DBREF necessary?

Dbref in my opinion should be avoided when work with mongodb, at least if you work with big systems that require scalability.

As i know all drivers make additional request to load DBRef, so it’s not ‘join‘ within database, it is very expensive.

Is there a way to reference other documents without having the
somewhat redundant $ref-field?

Yes, keep references in the mind, create naming conventions for ‘foreign keys‘ (something like RefUserId or just UserId) and store just id of referenced document. Load referenced documents yourself when needed. Also keep your eyes open for any denormalization, embedding you can do, because it’s usually greatly improve performance.

Leave a Comment