Queries with MongoDB


Good afternoon, I have the following concern:

I have defined a POJO as you see it below:

private String idInformacion;
@Indexed(direction = IndexDirection.ASCENDING)
private Pais pais;
private Date fechaCreacion;
private String nombre;
private String sexo;
private Date fechaNacimiento;
private List<Preferencias> preferencias;
private String numTelefono;
@Indexed(unique = true)
private String usuario;
private List<RedesSociales> redes;
private String contraseniaTW;
private String contraseniaFB;
private String contraseniaIG;
private Grupo grupo;
private String paqChip;
private String email;
private String contraseniaMail;
private String fuente;
private Date fechaRecarga;

As you can see the attributes Preferencias and RedesSociales are defined as type List, to access the values stored in the B.D I use an interface that extends the class MongoRepository and use the method findAll() . Now the problem is that these aforementioned attributes are returned in this way: (Since they have more than one value) [Preferencias(nombrePref=Rock), Preferencias(nombrePref=Tatuajes)]

This would not be a problem but when presenting them on the website it is annoying to see them in this way. My question is how could I make these values that are in a list only get the internal value, that is to say in preferences only get Rock or Tatuajes since it is the value that I want to present in the web page, what I tried it since the finAll is a List to get the values with their respective get but a lot of data does not seem efficient. Can you generate a query in Mongo to get all the stored values but the attributes defined as List bring them as a concatenated String? is to say something like this = Rock - Tatuajes

asked by Bryan Saltos 27.12.2018 в 22:45

0 answers