我想检索其“价格”字段介于某个最大值和最小值之间的数据,我在 java 中使用下面的语法,但它似乎不起作用。
>
BasicDBObject numeralQ;
List<DBObject> clauses = new ArrayList<DBObject>();
.
.
.
.
numeralQ.put(datafield,new BasicDBObject("$gt", min).append("$lt", max));
clauses.add(numeralQ);
.
.//i also have many other conditions that i want to "OR" them with this condition
.
BasicDBList or = new BasicDBList();
for (DBObject clause : clauses)
or.add(clause);
DBObject query = new BasicDBObject("$or", or);
DBCursor cur = coll.find(query);
while (cur.hasNext()) {
System.out.println(cur.next());
}
你能看出我在做什么错吗?
- 编辑
printing the `query.toString();` results in this string :
{ "$or" : [ { "Price" : { "$gt" : "2" , "$lt" : "1250"}}]}