Update + aggregation

97 views
Skip to first unread message

David Bouyssié

unread,
Apr 19, 2021, 11:18:04 AM4/19/21
to ReactiveMongo - http://reactivemongo.org
Hi there,

I would like to combine updateMany with aggregation features.
It seems to be available since version 4.2 according to StackOverflow:

I would like to do something very similar to the mentioned example:

db.collection.updateMany( {}, [{ "$set": { "dateField": { "$toDate": "$dateField" } }] );

Is it possible to write this with the ReactiveMongo API?
And if yes, since which specific version?

Thanks!

David

David Bouyssié

unread,
Apr 19, 2021, 11:48:13 AM4/19/21
to ReactiveMongo - http://reactivemongo.org

Cédric Chantepie

unread,
Apr 19, 2021, 5:16:37 PM4/19/21
to ReactiveMongo - http://reactivemongo.org
Please have a look at the documentation to update many documents.

Jack Roper

unread,
May 4, 2021, 9:09:21 AM5/4/21
to ReactiveMongo - http://reactivemongo.org
Having looked at the documentation and source code, I can't see how to pass an aggregation to the update methods. It seems like the required pack.Writer types are expected to work with just Document currently. I'm trying to make use of this mongo 4.2 feature: https://docs.mongodb.com/manual/reference/method/db.collection.update/#std-label-update-method-agg-pipeline

Apologies if I've missed something!

Cédric Chantepie

unread,
May 4, 2021, 9:23:36 AM5/4/21
to ReactiveMongo - http://reactivemongo.org
A restricted sub-pipeline in update, only supported by MongoDB +4.2, is not supported for.

Jack Roper

unread,
May 4, 2021, 10:41:08 AM5/4/21
to ReactiveMongo - http://reactivemongo.org
Got it -- thanks! Are there currently aren't any plans to support it in the future? It looks like custom commands are the way to go for now, as suggested above.

Cédric Chantepie

unread,
May 4, 2021, 1:58:23 PM5/4/21
to ReactiveMongo - http://reactivemongo.org
On Tuesday, 4 May 2021 at 16:41:08 UTC+2 Jack Roper wrote:
Got it -- thanks! Are there currently aren't any plans to support it in the future? It looks like custom commands are the way to go for now, as suggested above.

I don't think so.
Anything that can be written as BSON can be passed as update operator, and any aggregation stage can be written as BSON ... CQFD without specific API change.

collection.update(q = BSONDocument(...), u = coll.AggregationFramework.ReplaceRootField("newRootField"))
Reply all
Reply to author
Forward
0 new messages