在我的Spring Boot / Spring Data MongoDB项目中,我有以下POJO:
@Document(collection = "decision_analysis")
public class DecisionAnalysis {
private String id;
private DecisionAnalysisRequest decisionAnalysisRequest;
private DecisionMatrixPageResponse decisionMatrixPage;
private Date createDate;
private HttpRequestData httpRequestData;
...
}
其中DecisionAnalysisRequest
:
public class DecisionAnalysisRequest implements Serializable {
private static final long serialVersionUID = 1493180175756424789L;
private String decisionNameFilterPattern;
private Set<BaseQuery> filterQueries;
private Set<Long> sortCriteriaIds;
private String sortWeightCriteriaDirection;
private String sortTotalVotesCriteriaDirection;
private Map<String, Double> sortCriteriaCoefficients;
private Long sortCharacteristicId;
...
}
我需要通过DecisionAnalysis
查找DecisionAnalysisRequest
文档,因此我使用以下方法创建了一个Spring Data MongoDB存储库:
@Repository
public interface DecisionAnalysisRepository extends MongoRepository<DecisionAnalysis, String> {
DecisionAnalysis findByDecisionAnalysisRequest(DecisionAnalysisRequest decisionAnalysisRequest);
}
现在,此方法仅在filterQueries
为空时才有效。但是当filterQueries
不为null时,该方法将不断返回任何结果。
filterQueries
是一个复合对象数组,例如:
"filterQueries":[
{
"type":"AnyInQuery",
"characteristicId":711903,
"characteristicName":"Body type",
"value":[
"Compact"
],
"operator":"OR"
},
{
"type":"RangeQuery",
"characteristicId":712745,
"characteristicName":"Sensor photo detectors (megapixels)",
"value":[
10,
53
]
}
]
我做错了什么以及如何调整我的代码,以便DecisionAnalysis
正确查找DecisionAnalysisRequest
文档,即使filterQueries
包含数据也是如此。
更新
这是我将用作密钥的示例DecisionAnalysisRequest
文档(本文档内的信息因用户界面上每个用户选择而异):
{
"sortCriteriaIds":[
711882,
711887,
711884,
711899,
711896,
711897,
711890,
711891,
711888,
711889,
711895,
711892,
711893
],
"sortCriteriaCoefficients":{
},
"pageNumber":0,
"pageSize":10,
"sortWeightCriteriaDirection":"DESC",
"sortid":null,
"sortCharacteristicDirection":null,
"sortDecisionPropertyName":null,
"sortDecisionPropertyDirection":null,
"decisionsIds":[
],
"persistent":true,
"includeChildids":null,
"excludeChildids":null,
"filterQueries":[
{
"type":"AnyInQuery",
"characteristicId":711913,
"characteristicName":"Body material",
"value":[
"Aluminium alloy",
"Brass",
"Carbon fiber"
],
"operator":"OR"
},
{
"type":"AnyInQuery",
"characteristicId":711903,
"characteristicName":"Body type",
"value":[
"Compact SLR",
"Compact"
],
"operator":"OR"
},
{
"type":"EqualQuery",
"characteristicId":712746,
"characteristicName":"Sensor size",
"value":"1/1.7\" (7.44 x 5.58 mm)"
},
{
"type":"AnyInQuery",
"characteristicId":712895,
"characteristicName":"Color space",
"value":[
"Adobe RGB",
"ECI RGB",
"Primary color space"
],
"operator":"OR"
},
{
"type":"AnyInQuery",
"characteristicId":712145,
"characteristicName":"Other resolutions",
"value":[
"1008 x 672",
"1024 x 1024",
"1024 x 576"
],
"operator":"OR"
},
{
"type":"AnyInQuery",
"characteristicId":712738,
"characteristicName":"Image ratio w:h",
"value":[
"1:1",
"3:2",
"4:3"
],
"operator":"OR"
},
{
"type":"RangeQuery",
"characteristicId":712744,
"characteristicName":"Effective pixels (megapixels)",
"value":[
9,
44
]
},
{
"type":"EqualQuery",
"characteristicId":712901,
"characteristicName":"Color filter array",
"value":"RGB color filter array"
},
{
"type":"EqualQuery",
"characteristicId":712921,
"characteristicName":"Image stabilization",
"value":"Sensor-shift"
},
{
"type":"AnyInQuery",
"characteristicId":712944,
"characteristicName":"Uncompressed format",
"value":[
"No",
"RAW",
"TIFF"
],
"operator":"OR"
},
{
"type":"AnyInQuery",
"characteristicId":712928,
"characteristicName":"Image parameters",
"value":[
"Brightness",
"Color",
"Color Space",
"Color Tone",
"Contrast"
],
"operator":"OR"
},
{
"type":"RangeQuery",
"characteristicId":712919,
"characteristicName":"White balance presets",
"value":[
2,
10
]
},
{
"type":"RangeQuery",
"characteristicId":712917,
"characteristicName":"Boosted ISO (minimum)",
"value":[
1762,
10741
]
},
{
"type":"AnyInQuery",
"characteristicId":712950,
"characteristicName":"File format",
"value":[
"3FR",
"AGIF",
"ARW"
],
"operator":"OR"
},
{
"type":"RangeQuery",
"characteristicId":712918,
"characteristicName":"Boosted ISO (maximum)",
"value":[
339298,
2878034
]
},
{
"type":"RangeQuery",
"characteristicId":713340,
"characteristicName":"Normal focus range (cm)",
"value":[
22,
131
]
},
{
"type":"EqualQuery",
"characteristicId":713343,
"characteristicName":"Lens mount",
"value":"Leica M"
},
{
"type":"AnyInQuery",
"characteristicId":713325,
"characteristicName":"Autofocus",
"value":[
"Center",
"Continuous",
"Contrast Detect (sensor)",
"Face Detection",
"Live View"
],
"operator":"OR"
},
{
"type":"RangeQuery",
"characteristicId":713341,
"characteristicName":"Macro focus range (cm)",
"value":[
19,
75
]
},
{
"type":"RangeQuery",
"characteristicId":713342,
"characteristicName":"Number of focus points",
"value":[
78,
468
]
},
{
"type":"RangeQuery",
"characteristicId":713388,
"characteristicName":"Viewfinder resolution (dots)",
"value":[
633548,
3722581
]
},
{
"type":"RangeQuery",
"characteristicId":713386,
"characteristicName":"Viewfinder coverage %",
"value":[
84,
97
]
}
]
}
答案 0 :(得分:1)
查询在服务器端运行,因此您必须从服务器端的角度研究性能。
对于文档连续数据增长,您将达到16MB内存限制。
您必须使用点表示法来访问filterQueries
嵌入式文档以进行比较。
以下示例,如果您想匹配其中一个过滤器。
@Query("{decisionAnalysisRequest.filterQueries :?0}")
DecisionAnalysis findByDecisionAnalysisRequest(BasicQuery filter);
您将输入DecisionAnalysisRequest
与具有更多DecisionAnalysisRequest
的数据库filterQueries
进行比较时未收到回复的原因。
您应该查看文档/嵌入式文档/嵌入式阵列上的字段的比较标准,以比较整个文档/嵌入式文档/嵌入式阵列。