Project as nested document in spring mongo

前端 未结 1 1238
梦如初夏
梦如初夏 2021-01-23 14:36

I\'m looking for a translator to change this :

getCollection(\'migrate\').aggregate([  
{ \"$project\": {  
\"Contrat\": {\"Field1\":\"$Field1\", \"Field2\":\         


        
相关标签:
1条回答
  • 2021-01-23 15:02

    You can use below aggregation.

    AggregationOperation project = Aggregation.project().
             and("Contrat").nested(Fields.fields("Field1","Field2")).
             and("Formule").nested(Fields.fields("Field3","Field4"));
    AggregationOperation project2 = Aggregation.project().
             and("Contrats").nested(Fields.fields("Contrat","Formule")).
    AggregationOperation out = Aggregation.out("test");
    
    Aggregation aggregation = Aggregation.newAggregation(project, project2, out);
    mongoTemplate.aggregate(aggregation, "<nameOfInitialCollection>", Class.class);
    
    0 讨论(0)
提交回复
热议问题