是什么名字" count"并且"找到"当我将DBRef与java.util.map一起使用时查询?
在我的例子中,countByFoos-Method总是返回0而不是1。
如何通过给定的FooDao找到并统计BarDaos?
public class FooDao {
@Id
private String id;
private String key;
...
}
public class BarDao {
@Id
private String id;
@DBRef
private Map<String, FooDao> foos;
...
}
public interface FooRepository extends MongoRepository<FooDao, String> {
...
}
public interface BarRepository extends MongoRepository<BarDao, String> {
long countByFoos(FooDao fooDao);
...
}
public void doSomthing() {
FooDao foo = new FooDao("fooId1", "key1");
fooRepository.save(foo);
BarDao bar = new BarDao("barId1");
bar.addFoo(foo.getKey(), foo);
barRepository.save(bar);
int count = barRepository.countByFoos(foo);
}