以下のコレクションの日付を比較しようとしています
$db.notifications.find() { "_id" : ObjectId("51a4467be4b0142fc8b80eda"), "time" : "Tue May 28 11:24:03 IST 2013", "KEY" : "VALUE1" } { "_id" : ObjectId("51a4467be4b0142fc8b80edb"), "time": "Tue May 28 11:24:03 IST 2013", "KEY": "VALUE2" }
使用して
$db.notifications.find({ "time" : { "$gt" : "Fri May 31 00:00:00 IST 2013"}})
しかし、私が観察しているのは、「時間」を日付ではなく文字列として扱うことを比較しているため、2番目のコマンドが両方のエントリを返していることです。
$ db.notifications.find({ "time" : { "$gt" : "Fri May 31 00:00:00 IST 2013"}}) { "_id" : ObjectId("51a4467be4b0142fc8b80eda"), "time" : "火曜日 5 月 28 日 11:24:03 IST 2013", "KEY": "VALUE1" } { "_id": ObjectId("51a4467be4b0142fc8b80edb"), "time": "火曜日 5 月 28 日 11:24:03 IST 2013","キー" : "値2" }
正しいクエリを教えてください。また、その正しいバージョンを Java で記述する方法も教えてください。
どうもありがとう !!
EDIT1:
以下のコードを使用して日付を保存しています
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
dateFormat.setLenient(false);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String nowString = dateFormat.format(new Date());
Date nowDate = dateFormat.parse(nowString);
input.put("formattedDate", nowDate);
DBCollection collection = db.getCollection(<collection name>);
DBObject dbObject = (DBObject) JSON.parse(input.toString());
collection.insert(dbObject);"
およびクエリを使用して
DBObject query = QueryBuilder.start().put("formattedDate")
.greaterThan(prevDate).get();
DBCursor cursorDocJSON = collection.find(query);
「時間」を日付のみとして保存していることがわかります。なぜまだ問題があるのですか?