Announcement Announcement Module
No announcement yet.
resolving simple mongodb references in spring w/o dbref Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • resolving simple mongodb references in spring w/o dbref

    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.

  • #2
    You have to do the join yourself, which is what MongoDB (documentation) considers an application-level-join. If you just annotate a domain object's property with @DBRef you get the link resolved eagerly by our MappingMongoConverter.

    In general, i think "slow" in this scenario means "slower than embedding" but not slower than doing the application level join. If it really was slower than the app-level-join, why wouldn't mongo perform such a "join" instead of looking up the DBRef the way they do now .