5

Let's assume that I have the following documents in mongodb in the employees collection:

db.employees.insert({_id: ObjectId("4d85c7039ab0fd70a117d733"), name: 'Siona',
manager: [ObjectId("4d85c7039ab0fd70a117d730"), ObjectId("4d85c7039ab0fd70a117d732")] })

Here, 'Siona' has two managers, indicated in the managers array. I know that Spring Data M3 has the concept of DBRefs, but the monogdb documentation indicates that DBrefs are expensive, and that we should just store ObjectId when possible.

My question is, is there any way to resolve the document that the objectID here is pointing to via the Spring Data Document api, or am I forced to perform a join on the client side, where:

  • We get the document that has the name:"Siona"
  • Go back to the database to resolve each of the ObjectId's that represent Siona's managers.
Praveen R.
  • 241
  • 4
  • 15
  • From the mongodb documentation: "DBRef is a more formal specification for creating references between documents. DBRefs (generally) include a collection name as well as an object id. Most developers only use DBRefs if the collection can change from one document to the next. If your referenced collection will always be the same, the manual references outlined above are more efficient." http://www.mongodb.org/display/DOCS/Database+References – Praveen R. Aug 30 '11 at 01:59

1 Answers1

3

Posted the same question in the Spring forums, and one of their community members responded:

http://forum.springsource.org/showthread.php?113968-resolving-simple-mongodb-references-in-spring-w-o-dbref

We have to do the join ourself on the client side, if we don't use dbref.

Praveen R.
  • 241
  • 4
  • 15