0
@Query("{'recibido' : null ,'activo' : true}")
public List<Long> findEmpleadosPrlActivoRecibidoIsNull();

I want you to return a list with the "employee_id" attribute of each object and not the whole object.

Can somebody help me.

Thank you.

Jose
  • 1,779
  • 4
  • 26
  • 50

2 Answers2

1

You need to specify projection to select specific fields in result.

If you want to return only employee_id, your query will look like this:

db.collection.find({}, {employee_id:1, _id:0})

In Java API sepcified in doc above it will be:

collection.find().projection(fields(include("employee_id"), excludeId()))
Atish
  • 4,277
  • 2
  • 24
  • 32
0

Create a DTO that has an attribute with the same name that you want it to return

@Query("{'recibido' : null ,'activo' : true}")
public List<EmpleadoIdDTO> findIdsEmpleadosPrlActivoRecibidoIsNull();

public class EmpleadoIdDTO {
 private Long empleadoId;

 public Long getEmpleadoId() {
   return empleadoId;
 }

 public void setEmpleadoId(Long empleadoId) {
   this.empleadoId = empleadoId;
 }

}

Jose
  • 1,779
  • 4
  • 26
  • 50