双向引用总是牵强的Doctrine MongoDB


Bi-Directional References are always fetched Doctrine MongoDB

Symfony2项目与Doctrine MongoDB ODM:

我有以下文件:

用户

referenceOne:
    my_buddy:
        targetDocument: Buddiness #(just an example)
        mappedBy: from_user
        simple: true
    buddy_with_me:
        targetDocument: Buddiness
        mappedBy: to_user
        simple: true

萌芽

referenceOne:
    from_user:
        targetDocument: User
        simple: true
        inversedBy: my_buddy
    to_user:
        targetDocument: User            
        simple: true
        inversedBy: buddy_with_me

对于每个经过身份验证的请求,我都有两个额外的查询:

db.Buddiness.find({ "from_user": ObjectId("...") }).sort([ ]).limit(1).limit();
db.Buddiness.find({ "to_user": ObjectId("...") }).sort([ ]).limit(1).limit();

我怎样才能摆脱这2个?

通常原则默认情况下应该使用延迟加载。

但我想你可以在这里找到答案。

删除mappedBy属性。