date insertion with play json

21 views
Skip to first unread message

Ronald Cirka

unread,
Aug 24, 2024, 11:55:58 AM8/24/24
to ReactiveMongo - http://reactivemongo.org
I am currently upgrading from an old version of reactive mongo, 0.12.7, to 1.1.0. In 0.12.7, I was able to serialize a Date into JSON and insert it into mongo with the following serializer:

implicit val mongoJodaWrites = new Writes[org.joda.time.DateTime] {
def writes(o: org.joda.time.DateTime): JsValue = {
Json.obj("$date" -> o.getMillis)
}

val jsObj = Json.toJson(obj)
coll.insert(jsObj)

And it would be inserted correctly in mongo as a Date. Now that I've upgraded, the date isn't inserted correctly, it is inserted as raw json, seemingly ignoring extended json . (see screenshots). 



Screenshot 2024-08-24 at 11.50.23 AM.png
Screenshot 2024-08-24 at 11.51.53 AM.png

Cédric Chantepie

unread,
Sep 12, 2024, 4:45:38 PM9/12/24
to ReactiveMongo - http://reactivemongo.org
The extended syntax need to be imported.
Reply all
Reply to author
Forward
0 new messages