Skip to content

AggregationUpdate : supported operations set, unset ok, but what about push ? #4876

@boly38

Description

@boly38

Hi 👋,

I'm relying on AggregationUpdate with ConditionalOperators and switchCases in order to update multiple documents in one shot.

This work well for set, unset, conditional set..
cf. doc or my example below:

AggregationUpdate update = AggregationUpdate.update()
                .set("updateTs").toValue(updateTs)
                .set("result").toValue(
		  ConditionalOperators.switchCases(
                    CaseOperator.when(In.arrayOf("$myArray.state").containsValue("VALA")).then("VALA"),
                    CaseOperator.when(In.arrayOf("$myArray.state").containsValue("VALB")).then("VALB")
		  ).defaultTo("UNKNOWN")
                )
                .unset("updateRequested");

UpdateResult result = mongoTemplate.updateMulti(query, update, ResultDocument.class);

Now, I want to add a push operation to my existing update,

ideally something like that:

// .push("myArray", newValueToPush);// no
// .set("myArray").toValueOf(Aggregation.group("myArray").push(newValueToPush));// unexpected usage

but I'm unable to find a way to do that
(push is available in common update, or else in newAggregation as for example group("myArray").push(..)).

Could you explain me if this is possible and then how to do that ?
or else mark this as improvement (if allowed by mongo for this kind of aggregation) ?

In advance thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.comstatus: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions