Mongodb Query选择DBRef字段

时间:2015-10-15 19:13:04

标签: java mongodb mongodb-query spring-data-mongodb

我有两个系列,答案零售商。答案使用DBRef参考零售商。我在查询答案集时只会选择零售商的shopName。如何实现这一目标。我试过下面的Spring代码

query.fields().include("answerText").include("id").include("retailer.$id")

但它根本没有吸引零售商。

@Document(collection="retailer")
@TypeAlias("retailer")
public class Retailer extends CommonDomainAttributes implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -2712025356211775960L;

    public Retailer() {
        // TODO Auto-generated constructor stub
    }

    @DBRef(lazy=true)
    @Indexed(background=true,name="RETAILER_USER",dropDups=true)
    private IdeaRealtyUser user;

    @DBRef(lazy=true)
    private List<Product> products;

    private String shopName;

    @DBRef(lazy=true)
    private Address address;

    @DBRef
    private Retailer parentRetailer;

}

@Document(collection="answer")
@TypeAlias("answer")
public class Answer extends CommonDomainAttributes implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 4195056255932348897L;

    /**
     * 
     */
    public Answer() {
        // TODO Auto-generated constructor stub
    }

    Question question;

    @DBRef
    @Indexed(background=true,name="ANSWER_RETAILER",dropDups=true)
    private Retailer retailer;

    @TextIndexed()
    @Indexed(background=true,name="ANSWER_ANSWRTEXT",dropDups=true)
    private String answerText;

}

0 个答案:

没有答案