Spring Data MongoDB - 过滤计数和求和子文档数组

时间:2017-06-13 20:27:59

标签: mongodb spring-data

给定以下类描述的MongoDB集合:

@Document(collection = "persons")
@TypeAlias("person")
public class Person {
    @Id
    private ObjectId _id = null;
    private String personName = null;
    private List<Account> accountsList = null;

    public ObjectId getId()
    {
        return _id;
    }

    public void setId(ObjectId id)
    {
        this._id = id;
    }
    public String getPersonName()
    {
        return personName;
    }

    public void setPersonName(String personName)
    {
        this.personName = personName;
    }

    public List<Account> getAccountsList()
    {
        return accountsList;
    }

    public void setAccountsList(List<Account> accountsList)
    {
        this.accountsList = accountsList;
    }
}

public class Account
{
    @Indexed(unique = false)
    private double amount = 0.0;
    private String description = null;

    public double getAmount()
    {
        return amount;
    }

    public void setAmount(double amount)
    {
        this.amount = amount;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }
}

使用Spring Data Mongodb,我该怎么做:

1)仅计算金额> 1的帐户数量X

2)仅检索金额&gt;的帐户X

3)仅将金额&gt;的总金额加起来。 X

任何帮助将不胜感激

0 个答案:

没有答案