Ich versuche, Agregation mit Feder mongodb Vorlage zu verwenden. Die Gruppierung muss auf der dritten Dokumentenebene erfolgen. Eingabedokument istAgrgregation mit mongoDBtemplate für verschachteltes Dokument
{
"_id": "59036b0fa036cc28c8e07db6",
"sections": [{
"srcName": "test1",
"data": [{
"srcKey": "",
"rowIdx": 0,
"values": [{
"srcDesc": "Assets"
},
{
"srcDesc": "NonAssets"
},
{
"srcDesc": "liabilities"
}
]
},
{
"srcKey": "01",
"rowIdx": 1,
"values": [{
"srcDesc": "NonAssets"
}]
}
]
}]
}
Wesentlichen Abfrage wie
select distinct(srcdesc) from document where srcName="test1";
laufen Ich möchte Bitte beachten Sie, dass srcDesc dritte Ebene der Verschachtelung ist. Ich versuche unter Java-Code
private MatchOperation getMatchOPeration(String sectionName){
Criteria criteira=Criteria.where("sectionName").in(sectionName);
return match(criteira);
}
private GroupOperation getGroupOperaion(){
return group("srcDesc").last("srcDesc").as("srcDesc");
}
private ProjectionOperation getProjectionOPeration(){
return project("srcDesc").and("srcDesc").previousOperation();
}
public List<SourceName> findAllSourceNamesBySection(String sectionName){
List<SectionsDocument> sourceNameList=new ArrayList<>();
MatchOperation matchOPeration=getMatchOPeration(sectionName);
GroupOperation groupOperation=getGroupOperaion();
ProjectionOperation projectionOperation=getProjectionOPeration();
AggregationResults<SectionsDocument> aggregationResults=
mongoTemplate.aggregate(Aggregation.newAggregation(
matchOPeration,
unwind("sections.data.values"),
groupOperation,
projectionOperation),StatDocument.class,SectionsDocument.class);
sourceNameList=aggregationResults.getMappedResults();
return new ArrayList<>();
}
Was ist dein Mongo-Server und die Frühlings-Mongo-Version? – Veeram
@veeram, ich bin mit org.springframework.boot \t \t \t Feder-boot-Starter-data-mongodb \t \t \t 1.5.1.RELEASE org.springframework.boot \t \t \t Feder-boot-Starter-data-mongodb \t \t \t 1.5.1.RELEASE –
Abhinav1singhal
Was ist deine Mongo Server Version? – Veeram