I tried converting my String ID to MongoDB ObjectID
public class relevancy_test extends Object implements Comparable {
public static voi
Here is an example that will serve you:
public List findAlls() {
List personas = new ArrayList();
MongoCollection collection = baseDato.database.getCollection("persona", BasicDBObject.class);
try (MongoCursor cursor = collection.find().iterator()) {
while (cursor.hasNext()) {
BasicDBObject theObj = cursor.next();
String _id = ((ObjectId) theObj.get("_id")).toHexString();
String nombre = (String) theObj.get("nombre");
String apellido = (String) theObj.get("apellido");
String usuario = (String) theObj.get("usuario");
String contrasenna = (String) theObj.get("contrasenna");
Persona persona = new Persona();
persona.setNombre(nombre);
persona.setApellido(apellido);
persona.setUsuario(usuario);
persona.setContrasenna(contrasenna);
personas.add(persona);
}
}
return personas;
}