0

「価格」フィールドが特定の最大値と最小値の間にあるデータを取得したいのですが、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"}}]}

4

1 に答える 1

4

価格を文字列ではなく数値として比較します。したがって、次のような条件オブジェクトで終了する必要があります。

{ "Price": {"$gt": 2, "$lt": 1250 } }
于 2012-05-19T13:48:14.563 に答える