Can DBRefs contain additional fields?
Posted
by Soviut
on Stack Overflow
See other posts from Stack Overflow
or by Soviut
Published on 2010-05-23T23:02:58Z
Indexed on
2010/05/23
23:11 UTC
Read the original article
Hit count: 326
I've encountered several situations when using MongoDB that require the use of DBRefs. However, I'd also like to cache some fields from the referenced document in the DBRef itself.
{$ref:'user', $id:'10285102912A', username:'Soviut'}
For example, I may want to have the username available even though the user document is referenced. This would provide me all the benefits of a single document approach; Faster querying and eliminating the need to do manual dereferencing in my code. While at the same time allowing me to use references where they make sense.
The idea being that when the referenced document is updated (a user changes their name, for example) my business layer can automatically update all the documents that reference it.
Ultimately, I'm wondering if it's considered good form to store additional fields on my DBRefs? Will it break anything? Will I lose my data each time a reference is rewritten? Will drivers like pymongo support it?
© Stack Overflow or respective owner