I came across several situations when using MongoDB that require the use of DBRefs. However, I would also like to cache some fields from the referenced document in the DBRef itself.
{$ref:'user', $id:'10285102912A', username:'Soviut'}
For example, I can have a username available even if it refers to a user document. This would provide me all the benefits of a single approach to the document; Speeding up queries and eliminating the need to do manual dereferencing in my code. At the same time, letting me use links where they make sense.
The idea is that when updating a reference document (for example, the user changes his name), my business layer can automatically update all documents that link to it.
Ultimately, I wonder if he thinks a good form for storing extra fields in my DBRefs? Will it break anything? Can I lose my data every time the link is rewritten? Will drivers like pymongo support him?
source share