I am doing a crud with SpringBoot and mongoDb in my local, I have added a record from the mongo console ->
db.articulo.save({"_id":ObjectId("90e"),"idPromocion":1,"numArticulos":"3","articulos":[{"nombre":"silla","color":"rojo","precio":"10€"},{"nombre":"mesa","color":"azul","precio":"2€"}],"entrega":"sabado"}
And now to make the crud I have created the model
@Document
public class Articulo {
private Integer idPromocion;
private Articulos art;
public Articulo(){}
public Articulo(Integer idPromocion,Articulos art){
this.idPromocion=idPromocion;
this.art=art;
}
getters.setter...
}
public class Articulos {
private String nombre;
private String color;
private String precio;
constructor, getter, setters
}
---------------
the repository
@Repository
public interface ArticuloRepository extends CrudRepository<Articulo, String>
{ }
Implementation
@Autowired
private ArticuloRepository repositorio;
List<Articulo> list= (List<Articulo>) repositorio.findAll();
Later in the execution I have checked the data of the list and I find the data to null, apparently it does not recover them correctly. I have another collection with a simpler structure and it does retrieve them for me.
MongoDB, being a type of non-relational database, has its own characteristics and, therefore, its own repository. In your case you must substitute
CrudRepository
forMongoRepository
that it has its own findAll that should work for you.