In the project I am currently working on, it seems to make more sense efficiency wise if I create a nested document that contains a list of "pointers" to information stored in other collections. That way this nested document can be easily used to retrieve a list of relevant information. The question is, how to do this? Is there a way to store locations of other information in a field in MongoDB? If not, could anyone suggest a scheme that is equally or more efficient? Thanks very much!
Asked
Active
Viewed 2,447 times
4
-
Store the reference as collection name plus the _id of the referenced record? – Alex Howansky Jul 06 '11 at 15:44
-
Is there something invalid about this question that warrants a downvote? DBRefs are not exactly ideal for this situation, but using how they work I can create a solution. – Ben Kulbertis Jul 06 '11 at 16:02
-
DBRefs are the only option you have. – Jul 06 '11 at 16:20
-
Have you thought about embedding those documents that you want to reference? – TTT Jul 07 '11 at 11:29
1 Answers
2
There is no GOOD way to do this. If this is what you're looking for, you should be using a relational database.
But if you HAVE to go by this route then, why not store ID's in a document, and then link those ID's to documents in the other collection.
Unfortunately, this would require you to do 2 separate queries, as Mongo does not support compound queries that span documents.

Dr. Xperience
- 475
- 1
- 5
- 18

ZacAttack
- 2,005
- 5
- 21
- 34