先贴测试代码!
public Date queryBeforeWeek(String routeId, Date d) throws Exception {
Query<BayonetFlowHis> q = ds.createQuery(BayonetFlowHis.class);
//q.and(q.criteria("routeId").equal(routeId),q.criteria("DateTime").equal(d));
q.filter("routeId", routeId);
q.field("DateTime").equal(d);
return q.asList().get(0).DateTime;
}
只要把q.field("DateTime").equal(d);注释掉,就可以成功返回结果。用filter方法也是一样!
不注释的话,logs就直接返回
2015-12-15 09:07:56.877 [org.mongodb.driver.protocol.query] [main] [DEBUG] - Sending query of namespace warningFlow.BAYONET_FLOW_HIS on connection [connectionId{localValue:2, serverValue:423}] to server 172.5.1.94:27017
2015-12-15 09:07:56.962 [org.mongodb.driver.protocol.query] [main] [DEBUG] - Query completed
mongodb用morphia框架具体如何让时间字段等于某个固定时间来查询呢?
|