Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

java - Spring data mongodb search for ISO date

I am trying to search for date of birth using query

criteria = Criteria.where("dob").lte(new DateTime().toDate());

And spring data mongodb generate below query:

MongoTemplate: find using query:

{ "dob" : { "$lte" : { "$date" : "2015-05-16T07:55:23.257Z"}}}

fields: null for class: class com.temp.model.User in collection: user

But I did not get any result.

My dob field in mongodb:

{"dob" : ISODate("1991-01-23T00:00:00Z")}

How I can search for dob in ISODate format ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Query would execute perfect from Spring data mongodb0

{ "dob" : { "$lte" : { "$date" : "2015-05-16T07:55:23.257Z"}}}.

But It will not execute from mongo CLI.

Query to execute on cli.

{dob:ISODate("2015-05-15T07:55:23.257Z")}

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...