MongoDB查询不起作用?

时间:2016-02-10 19:13:26

标签: java mongodb playframework dao mongify

我使用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;
}

根据方法,我传递了两个参数assignedToappointmentType。现在appointmentQuery将在db中进行搜索,并返回Appointment等于appointment.assignedtoassignedTo等于appointment.appointmetType的{​​{1}}个对象的列表{1}}。但每次我得到约会名单appointmentType的大小。

我重新确认了MongoDB中的这个集合并且它已存在。我在这做错了什么?我需要申请0吗?

0 个答案:

没有答案