I would recommend dropping the DBRef in favor of simply storing the _id referenced document, provided that you know the name of the referenced link.
There is absolutely no way to "resolve" the DBRef array from the server side (in one step) to MongoDB and requires that you skip the array on the client and individually allow each document.
Conversely, if you only store an array of reference _id , you can get that array and then use the $in query to retrieve all of them.
So your document might look like this:
{ "_id" : ObjectId("4e2d4892580fd602eb000003"), "date_added" : ISODate("2011-07-25T11:42:26.395Z"), "date_updated" : ISODate("2011-07-25T11:43:09.870Z"), ... "references": [ ObjectId(123), ObjectId(234), ObjectId(567), ObjectId(891) ], ... "name" : "some name" }
You can then query MongoDB using the contents of the references field:
db.somecollection.find({"_id": {"$in": references}})
Brendan W. McAdams
source share