While I am saving a normal string to mongo which has a decimal , I am able to persist to DB
Ex: {“price”:“20.00”}
But When I am trying to save list of decimals as a string which has precision ‘00’ (5.00) as list of strings, only one zero in precision can be able persist as below.
Ex:
{“values”:[
“6.0”,
“5.0”
]
}
Our DB Server version is 3.6.+
Trying with spring-data-mongodb version 1.8.+
Please help me out in this what could be the issue.
It will help if you post the code which you are using to store the string decimals into the array values. Also, please specify the MongoDB Java driver and Java versions.
As such MongoDB v3.4 started supporting the decimal data type - which is more conducive to store decimal numbers (e.g., using as monetary data).
I am using Java 8 version & org.mongodb:mongo-java-driver:2.13.3 & org.springframework.data:spring-data-mongodb:1.8.+::
Below is the code snippet:
List list = new ArrayList();
list.add(“6.00”);
list.add(“5.00”);
Query query = new Query(Criteria.where());
Update update = new Update();
update.set(“values”, list);
mongoOperations.upsert(query, update, ValuesPojo.class); or
mongoTemplate.upsert(query, update, ValuesPojo.class);
This is my class lets say it has get/set methods associated with variable.
myCollection–> is my collection name .
@Document(collection = “myCollection”)
public class ValuesPojo {
private List<String> values;
}
Everything is available but my data persisting is different. After precision it must be two ‘0’ s like “5.00” instead of “5.0” in my collection object array as mentioned…