我使用Mongify连接MongoDB和Play Framework。我写了一个简单的搜索方法,它可以帮助我在对它应用过滤器之后获取对象列表:
public List<Appointment> search(Long assignedTo, String appointmentType) {
List<Appointment> appointmentList = new ArrayList<>();
Query<Appointment> appointmentQuery = datastore.find(Appointment.class);
if (assignedTo > 0) {
appointmentQuery.field("assignedTo").equal(assignedTo);
}
if (null != appointmentType || (!appointmentType.isEmpty())) {
appointmentQuery.field("appointmentType").equal(appointmentType);
}
appointmentList = appointmentQuery.asList();
return appointmetList;
}
根据方法,我传递了两个参数assignedTo
和appointmentType
。现在appointmentQuery
将在db
中进行搜索,并返回Appointment
等于appointment.assignedto
且assignedTo
等于appointment.appointmetType
的{{1}}个对象的列表{1}}。但每次我得到约会名单appointmentType
的大小。
我重新确认了MongoDB中的这个集合并且它已存在。我在这做错了什么?我需要申请0
吗?