#1 2016-09-22 09:12:23

MrFresh
Member
Registered: 2016-09-22
Posts: 2

Updating record to mongoDB loses date format

Hello,

I'm having issues updating a record to mongo using mORMot.

- Application loads data from mongoDB in to a variant.

- Makes some modifications.

- Writes the data back to the DB.

The problem is that after the update the various date fields within the record (which haven't been modified in the app), are no longer recognised as date types - they are strings.

We fixed this issue during import, using this:

var
  data : variant;
  buffer : string;

...
data       := _JSon(RawUTF8(buffer), [dvoJSONParseDoNotTryCustomVariants]);
...

But it doesn't appear to work when writing back to the DB.

Any help would be appreciated!

Thanks!

Offline

#2 2016-09-22 18:58:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Updating record to mongoDB loses date format

It is highly depending on how you create the data.
If you use some plain _Json() content, you will only be transmitted JSON strings, not data.
This is as expected.
There is no schema involved, so there is no way of knowing the value type: there is no date/time type in JSON!

Use the DateToSQL() value to append the JSON_SQLDATE_MAGIC prefix to the string.
It will then be recognized as a date when converted back to BSON for MongoDB.

Offline

#3 2016-09-23 08:15:04

MrFresh
Member
Registered: 2016-09-22
Posts: 2

Re: Updating record to mongoDB loses date format

Thanks for the reply.

I'll have a look at using DateToSQL().

Offline

Board footer

Powered by FluxBB