gpt4 book ai didi

java - $and条件不适用于springboot mongodb中的三个或三个以上字段

转载 作者:太空宇宙 更新时间:2023-11-04 09:48:52 25 4
gpt4 key购买 nike

@Document(collection = "formtype")
public class FormType {
@Id
@Field(value = "id")
private Long formTypeId;

@Field(value = "formtypename")
private String formTypeName;

@Field(value = "isdeleted")
private Boolean isDeleted = false;

//with constructor and getter setter
}

我编写此查询是为了找出表单类型的记录,其中 formTypeName 不属于该 formTypeId 并且它的 isDeleted 不等于 true。

编写此查询时,即使该记录存在,我也会得到 null 值。 请帮帮我!

 @Query("{ '$and': [ {'formTypeId':{$ne :?0}} , {formTypeName:'?0'} , {'isDeleted':{$ne : true}} ] }") FormType getformTypeToUpdate(Long formTypeId,String formTypeName);

最佳答案

您将 ?0 括在简单的引号内,这可能会被编译器误解。另外,您似乎只对 formTypeIdformTypeName 两个条件使用了 Long formTypeId 参数。

你能尝试一下吗:

@Query("{ '$and': [ { 'formTypeId': { $ne : ?0 } }, { 'formTypeName': ?1 }, { 'isDeleted': { $ne : true } } ] }") 
FormType getformTypeToUpdate(Long formTypeId, String formTypeName);

关于java - $and条件不适用于springboot mongodb中的三个或三个以上字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55060412/

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