#1 2017-08-18 09:46:37

Hector
Member
Registered: 2017-08-18
Posts: 2

SynMongoDB float with quote problem

Hi,

i am using synmongoDB with good results.
but i have a problem with double :
quotes are added to json and if i create  an index on the geoson structure i have an error message : point must only contain numeric elements

"location":{"type":"Point","coordinates":["2.12454","48.12475"]}

if the double value have 4 or less decimals it is ok :

"location":{"type":"Point","coordinates":[2.1245,48.1247]}

the json send to mongodb is ok but the json in the database is wrong.

Do you have an idea to find a solution to this problem ?

Thanks by advance

Offline

#2 2017-08-18 11:55:25

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

Re: SynMongoDB float with quote problem

How did you create your data?
Check the documentation:

  // - by default, only integer/Int64/currency number values are allowed, unless
  // dvoAllowDoubleValue is set and 32-bit floating-point conversion is tried,
  // with potential loss of precision during the conversion

You need to explicitly set dvoAllowDoubleValue option when you create your TDocVariant data, or use a TBsonVariant container - e.g. by BSONVariant().

On newer versions of MongoDB, you can use the just included TDecimal128 kind of data, if double doesn't have enough precision.

Offline

#3 2017-08-18 12:13:01

Hector
Member
Registered: 2017-08-18
Posts: 2

Re: SynMongoDB float with quote problem

i create a TDocVariant from json :

doc := TDocVariant.NewJSON(aContent,[dvoValueCopiedByReference]);

i have added dvoAllowDoubleValue
doc := TDocVariant.NewJSON(aContent,[dvoValueCopiedByReference,dvoAllowDoubleValue]);
and it is now ok

I have searched in the source code of synCommons.pas but  this option has escaped my view

Thanks a lot

Offline

#4 2017-08-18 12:36:12

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

Re: SynMongoDB float with quote problem

Check https://synopse.info/files/html/Synopse … l#TITLE_42
I will try to make it more explicit.

If your purpose is to send directly the data to MongoDB (without any modification), calling BSONVariant() may be a better option, since it will directly encode the JSON into BSON - and handles double values.

Offline

Board footer

Powered by FluxBB