with mongo java driver for getting collection count, i use following method
public Integer getUsersCount() {
Integer listCount = 0;
try {
BasicDBObject query = new BasicDBObject();
DBCursor cursor = mongoCoreService.getUserCollection().find(query);
listCount = cursor.count();
} catch (Exception e) {
e.printStackTrace();
}
return listCount;
}
Now I try do the same with hibernate ogm, but I cant find example or implementation. I have entity manager
public int getProductCount() {
EntityManager em = getEntityManager();
try {
} finally {
//em.close();
}
return 10;
}
I tried with criteria API, but version what I use and which is work with Spring does not support criteria API. How can get collection count?
You can run the following native query for getting the collection size: