mongo-driver-3 icon indicating copy to clipboard operation
mongo-driver-3 copied to clipboard

Support aggregation pipelines for updates

Open matej-ibis-ai opened this issue 11 months ago • 0 comments

In my use case, I found I could benefit from a Mongo update (updateOne or updateMany) call where the update is an aggregation pipeline -- a list of operations rather than a single object defining the operation(s). While this is supported by the underlying Java library, it looks like this Clojure library doesn't expose that functionality; at least, the docstrings of the update-one and update-many say that the update argument should be a map, and passing a vector instead resulted in key errors.

I ended up using:

(require '[mongo-driver-3.collection :as mc])
(require '[mongo-driver-3.model :as mm])

(.updateOne (mc/collection db (get colls coll))
           (mm/document match-q)
           (if (map? update-q)
             (mm/document update-q)
             (mapv mm/document update-q))
           (mm/->UpdateOptions opts))

and that works, but it would be preferable to have this wrapped by this library and exposed as a ready function (including session handling, which I didn't care about in my use case).

matej-ibis-ai avatar May 21 '25 07:05 matej-ibis-ai