Sign In Register

How can we help you today?

Start a new topic
Answered

How do I query timestamp properties like "created" in "player" collection

I would like to know how to build a query to select players with a creation date greater than a certain timestamp value.

In the NoSQL interface I tried the following but it's not working:


Collection: player

Query: {created: {$gt: 1422075600}}


Best Answer

When querying date fields, you need to let mongo know the type you are looking for. This requires wrapping the epoch time in a $date and a $numberLong


{"created":  { "$gt" : {   "$date": {    "$numberLong": "1427748260201"   } } } }


1 person has this question

In the Tech Support's example, make sure you specify the timestamp value in String, or you'll get an error response like "java.lang.Long cannot be cast to java.lang.String".

Answer

When querying date fields, you need to let mongo know the type you are looking for. This requires wrapping the epoch time in a $date and a $numberLong


{"created":  { "$gt" : {   "$date": {    "$numberLong": "1427748260201"   } } } }

Login to post a comment