gpt4 book ai didi

java - 查找所有 UUID MongoRepository

转载 作者:行者123 更新时间:2023-12-02 11:49:00 26 4
gpt4 key购买 nike

我正在尝试使用 mongo-spring-boot 实现 findAllByUUID,但没有运气。我有什么:

public interface CarMatchRepository extends MongoRepository<CarMatchEntity, String> {
List<CarMatchEntity> findAllByCarID(Iterable<UUID> ids);
CarMatchEntity findByCarID(UUID carID);
}

函数调用:

public void addCarsToCollection(String id, List<UUID> carId) {
List<CarMatchEntity> entities = carMatchRepository.findAllByCarID(carId); <--- empty
}

如果我调用 findByCarID() ,它会正确检索单个对象(如果存在),但使用 Iterable 查询不会失败,但它永远不会返回任何对象。我在这里做错了什么,还是我为这个问题走错了路?

谢谢!

编辑:

@Document(collection = "car_index")
public class CarMatchEntity implements Serializable {

@Id
private String id;

private UUID carID;

//partner data
private UUID partnerID;
private String partnerThumbURL;
private String partnerName;
private Date partnerMembershipSince;

// car location
private List<Double> location;
private String district;
private String city;

// car data
private CarType carType;
private String carBrand;
private String carModel;
private String carPlate;
private List<CarFeature> carFeatures;

private String carAddress;

private String description;
private BigDecimal hourFare;
private BigDecimal dayFare;
private BigDecimal weekFare;
private BigDecimal dailyPrice;
private BigDecimal suggestedHourlyPrice;
private BigDecimal suggestedDailyPrice;
private BigDecimal suggestedWeeklyPrice;
private String carThumbURL;
private Map<String, CarPhotos> carPhotosURL;
private CarAvailability availability;
private CarStatus carStatus;
private String carYear;
private FuelType fuelType;

@Transient
private DayOfWeek prohibitedDay;

private String carYearModel;

@Transient
private double partnerRating = 5.0;
private CarTransmission carTransmission;
private CarColor carColor;
private String odometer;
private Integer manufactureYear;
private String fipeCode;
private String renavam;
private String chassi;
private InsuranceCompany insuranceCompany;
private List<CarSpecialFeature> carSpecialFeatures;
private BigDecimal deductible;
private Boolean superCar;

public CarMatchEntity() {

}

最佳答案

尝试将基于 JSON 的查询与 SpEL 表达式结合使用

@Query("{carID: { $in: ?0 } })")
List<CarMatchEntity> findAllByCarIds(List<UUID> ids);

关于java - 查找所有 UUID MongoRepository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48010761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com