user1757885
user1757885

Reputation: 1

Storing date field from JSON to MongoDB using Java API

I am using java api for mongodb to parse the JSON string into Java object and storing it into MongoDB.

My JSON string will have fields that are date like the one given below. "created":"2012-10-17 21:39:06.385987 +0000"

When I try to save the parsed java object into MongoDB it stores the value as String. I would like to store it has a datetime field. Can someone shed some light on this?

Thanks and Regards, Balaji.R

Upvotes: 0

Views: 3519

Answers (1)

mrówa
mrówa

Reputation: 5781

Java driver, as other default drivers, maps basic language types to MongoDB types, so to save date to mongo, you just need to save the Date object, not date string. Here's simple sample from MongoDB documentation.

Upvotes: 1

Related Questions