简体   繁体   English

在春天解决mongodb参考

[英]resolving mongodb references in spring

Let's assume that I have the following documents in mongodb in the employees collection: 我们假设我在employees集合中的mongodb中有以下文档:

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

Here, 'Siona' has two managers, indicated in the managers array. 在这里,'Siona'有两个经理,在经理阵列中表示。 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. 我知道Spring Data M3具有DBRefs的概念,但monogdb文档表明DBrefs很昂贵,我们应该尽可能存储ObjectId。

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: 我的问题是,有没有办法解决这里的objectID通过Spring Data Document api指向的文档,或者我被迫在客户端执行连接,其中:

  • We get the document that has the name:"Siona" 我们得到的文件名称为:“Siona”
  • Go back to the database to resolve each of the ObjectId's that represent Siona's managers. 返回数据库以解析代表Siona经理的每个ObjectId。

Posted the same question in the Spring forums, and one of their community members responded: 在Spring论坛上发布了同样的问题,其中一位社区成员回复了:

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

We have to do the join ourself on the client side, if we don't use dbref. 如果我们不使用dbref,我们必须在客户端进行自己的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM