0

All I'm trying to do is to parse very simple json line, even its valid i dont know why its throwing an error

the line is

com.mongodb.util.JSONParseException: 
{publish_status:'active',activation_date:{$lt:new Date()},expiration_date:{$gt:new Date()}}
                                               ^

what is wrong with the new Date() as a value?

2
  • Yep, that isn't valid JSON. Commented Mar 3, 2013 at 15:11
  • @poitroae I'm trying to get the records that has activation date less than now and expiration date grater than now ... Commented Mar 3, 2013 at 16:59

2 Answers 2

3

That's not valid JSON at all. JSON syntax is defined on json.org, and it's always a string key with a value that's one of a string, number, boolean, null, array, or object. You're writing a Mongo query from Java. You should reformulate your question and retag appropriately.

Sign up to request clarification or add additional context in comments.

Comments

1

I tried using the new date() in mongo DB 2.2.3 directly and it worked .. it created a value of ISODate.

You may try using this:

{publish_status:'active',activation_date:new Date(),expiration_date:new Date()}

3 Comments

I need the $lt & $gt operators,
Date date = new Date(); BasicDBObject query = new BasicDBObject(); query.put("expiration_date", BasicDBObjectBuilder.start("$gt",date).get()); query.put("activation_date", BasicDBObjectBuilder.start("$lt",date).get()); DBObject document = collection.findOne(query);
Try out the above code .. i used Java 1.7 and mongo dB 2.2.3 and mongo driver as 2.10.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.