Hi Will,
Used '"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" format to store the dates into db.
Using the following code for querying. date1 and date2 are java.util.date objects. queryBuilder.put(searchKey).greaterThanEquals(date1).lessThanEquals(date2);
public List query(Criteria criteria, String storeName) {
List<DBObject> dbCriterias = getCriterias(criteria);
printQuery(dbCriterias, storeName);
AggregationOutput output = dbCollection.aggregate( dbCriterias);
List results = output.results();
return results;
}
// Prints the query so that it can be verified in client tools
//Date queries may not work in some tools if they support only javascript as they need isodate instead of the generated one.
public void printQuery(List<DBObject> criterias, String storeName) {
if(criterias != null && !criterias.isEmpty() ) {
System.out.println("\n pipelineOps:" + " db." + storeName + ".aggregate(" +
criterias.toString().substring(1, criterias.toString().length() - 1 ) + ");");
}
}
Thanks
MokshYou say:
Used '"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" format to store the dates into db.
But that's a string and not a date so it won't match a query on date range.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/2b06fb1f-06c9-48e7-8ef5-b0b2f031a9f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.