Force Variable Type MongoDB (Java)

0

I would like to know if there is any method to "force" the type of variable within MongoDB in Java . I need to insert a Document with certain data, example:

Document doc = new Document();
// Forzar que guarde Rut como Integer siendo que recibe un Strig
doc.append("RUT","123456789");

Does anyone know anything?
Thanks!

    
asked by Daniel Piña Rivera 29.05.2018 в 00:12
source

1 answer

0

If you want to convert the value of RUT to Integer you need the method parseInt of class Integer , as in the following code:

Document di = new Document();
//Se realiza la conversión del datos de String a Integer
di.append("RUT",Integer.parseInt("123456789"));
    
answered by 29.05.2018 в 00:31