gpt4 book ai didi

mongodb - 查询路径深度

转载 作者:可可西里 更新时间:2023-11-01 09:52:24 28 4
gpt4 key购买 nike

我有一个包含 DocumentValue 列表的实体 Document

@QueryEntity
@Document
public class Document{
private List<DocumentValue> documentValues;
}

DocumentValue 也可以有一个 DocumentValue 列表

@QueryEntity
public class DocumentValue {
String value;
String name;
String id;
List<DocumentValue> documentValues;
}

我现在正在尝试做类似的事情

private QDocumentValue getDocumentValuePathByDepth(int depth){
ListPath path = QDocument.document.documentValues;
if (depth != null) {
for (int i = 0; i < depth; i++) {
path = path.documentValues.any();
}
}
}

有人知道是否可以在那个深度进行 eleMatch 吗?

喜欢

ListPath<QDocumentValue> query = getDocumentValuePathByDepth(5);
return query.fieldId.eq(documentFilter.getFieldId()).and(query.value.between(from, to));

该深度的 documentValues 的一个元素应该满足这两个条件

BR 哥伦比亚特区

最佳答案

像这样在 Querydsl Mongodb 中支持 elemMatch

QDocumentValue documentValue = QDocumentValue.documentValue;
query.anyEmbedded(document.documentValues, documentValue)
.on(documentValue.id.eq(documentFilter.getFieldId(),
documentValue.value.between(from, to));

关于mongodb - 查询路径深度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20612028/

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