MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Utilizzo di più sfaccettature in MongoDB Spring Data

Puoi concatenare operazioni su più faccette usando .and() e .as() metodi. Dovresti sostituire il secondo facet metodo con and metodo come di seguito.

FacetOperation facets = facet(match(where("entryType").is(EntryType.DEBIT)
        .andOperator(where("currentStatus").is(TransactionStatus.CONFIRMED))),
        unwind("history"),
        match(where("history.status").is(TransactionStatus.CONFIRMED)),
        project().andExpression("history.amount").as("historyAmount"),
        group().sum("historyAmount").as("total"),
        project("total")
).as("totalConfirmedDebits"),
        /*
                 * Summarize Confirmed Credits 
         */
.and(match(where("entryType").is(EntryType.CREDIT)
        .andOperator(where("currentStatus").is(TransactionStatus.CONFIRMED))),
        unwind("history"),
        match(where("history.status").is(TransactionStatus.CONFIRMED)),
        project().andExpression("history.amount").as("historyAmount"),
        group().sum("historyAmount").as("total"),
        project("total")
).as("totalConfirmedCredits")