BSONDocument and strict mode

19 views
Skip to first unread message

Paul Campbell

unread,
Jan 6, 2016, 11:42:51 AM1/6/16
to ReactiveMongo - http://reactivemongo.org
Anyone know it its possible to for a BSONDocument to apply full strict to shell mode conversion, as currently it only seems to convert _id and nothing else (such as dates) ?.

I want to do something like this ...

Lets say I have the following json in a JsValue. Its a JsValue because I'm using play and have some http request payload as a JsValue and I want to store it directly as json in mongo without having to map it to a case class.

{
  "_id": {"$oid": "568d23c9af4b609901aad7a2"},
  "createdDate" : {"$date" : "2016-01-06T14:25:13.526Z"},
}

When I do:

collection.insert(BSONFormats.BSONDocumentFormat.reads(theJsValue).get)

What I get stored in mongo is:
 
{
    "_id" : ObjectId("568d23c9af4b609901aad7a2"),
    "createdDate" : {
        "$date" : "2016-01-06T14:25:13.526Z"
    }
}

When what I really want is:

{
    "_id" : ObjectId("568d23c9af4b609901aad7a2"),
    "createdDate" : ISODate("2016-01-06T14:25:13.526Z")
    }
}

In other words the only strict-to-shell mode conversion being done is the _id - dates are not being converted. I need the full set of strict mode conversions.

Any ideas ?.





Cédric Chantepie

unread,
Jan 7, 2016, 3:15:18 AM1/7/16
to ReactiveMongo - http://reactivemongo.org
Hi,

The JSON conversion provided (by the JSON serialisation pack; see http://reactivemongo.org/releases/0.11/documentation/tutorial/play2.html#main-features ) is from "$date": longInstant (numeric not a string).

Best regards

Cédric Chantepie

unread,
Jan 8, 2016, 8:38:41 PM1/8/16
to ReactiveMongo - http://reactivemongo.org
Reply all
Reply to author
Forward
0 new messages