You are not logged in.
Pages: 1
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
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
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
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
Pages: 1