SpringData MongoRepository Count和Where子句组合

时间:2017-12-01 12:53:52

标签: spring-data mongorepository

我正在使用MongoDb和SpringData MongoRepository ..我想获取计数器消息,其中receiver user =?和消息readed =? ...  简而言之,我想获取用户未被解决的消息。我的方法就像这样..但我不知道怎么做..消息是我的mongo文件..谢谢。

    public void OnGet()
    {
        Person p1 = GetPerson1();
        Person p2 = GetPerson2();

        p1.Age = 26;
        p2.Age = 26;

        Person p1_after = GetPerson1(); // not null, but p1_after.Age is 26
        Person p2_after = GetPerson2(); // null
    }

    public Person GetPerson1()
    {
        return _context
            .Persons
            .Where(p => p.Age == 25)
            .SingleOrDefault();
    }

    public Person GetPerson2()
    {
        return _context
            .Persons
            .ToList()
            .Where(p => p.Age == 25)
            .SingleOrDefault();
    }

1 个答案:

答案 0 :(得分:1)

答案是

int countFindByReadedAndReceiver(boolean readed, String receiver);