我试图从collection中获取所有记录。下面是代码供参考。
public class ParkingPlace{
@Id
private String id;
private String placeId;
@DateTimeFormat(iso = ISO.DATE_TIME)
private Date creationDate;
@DBRef
private List<Review> placeReviews;
// Getters and setters
}
public class Review{
@Id
private String id;
@DBRef
private Author reviewAuthor;
//getters and setters
}
public class Author{
@Id
private String id;
private String fullName;
//getters and setters
}
public class ParkingPlaceDAO{
@Autowired
MongoOperations mongoOperations;
public List<ParkingPlace> getAllPlaces() {
// new mongodb query
Query query = new Query();
// sort by date
query.with(new Sort(Sort.Direction.DESC, "creationDate"));
// run query
return mongoOperations.find(query, ParkingPlace.class);
}
}
因此,当我调用getAllPlaces()
方法时,它会在控制器中抛出
java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [reviewAuthor]
我已经检查了数据库和所有集合,还从mongo shell中解雇了它给了我结果。但不是通过代码