I'm using Clojure's Monger library to connect to a MongeoDB database.
I want to update, insert & remove subdocuments in my Mongo database. MongoDB's $push modifier lets me do this on the root of the searched document. But I want to be able to $push onto a sub-collection. Looking at Monger's tests, it looks possible. But I want to be sure I can push to the child-collection of the 3rd parent. Can Monger do something like this?
(mgcol/update mycollection { :my-criteria-key "my-criteria-value" } { $push { "parent.3.child-collection" "fubar" }} )
Even better would be the ability to have a $where clause in my $push. Is something like this possible?
(mgcol/update mycollection { :doc-criteria-key "doc-criteria-value" } { $push { { $where { parent.child.lastname: 'Smith' } } "fubar" } } )
But even on a basic level, when I try the following command in my repl, I get the below error.
The "fubar" database definitely exists
I'm definitely connected to the DB
The
{ :owner "fubar@gmail.com" }
criteria is definitely valid; andI tried both
"content.1.content"
and"content.$.content"
:
repl => (mc/update "fubar" { :owner "fubar@gmail.com" } { $push { "content.1.content" { "fu" "bar" } } } ) ClassCastException clojure.lang.Var$Unbound cannot be cast to com.mongodb.DB monger.collection/update (collection.clj:310) repl => repl => repl => (clojure.repl/pst *e) ClassCastException clojure.lang.Var$Unbound cannot be cast to com.mongodb.DB monger.collection/update (collection.clj:310) bkell.run.run-ring/eval2254 (NO_SOURCE_FILE:46) clojure.lang.Compiler.eval (Compiler.java:6406) clojure.lang.Compiler.eval (Compiler.java:6372) clojure.core/eval (core.clj:2745) clojure.main/repl/read-eval-print--6016 (main.clj:244) clojure.main/repl/fn--6021 (main.clj:265) clojure.main/repl (main.clj:265) user/eval27/acc--3869--auto----30/fn--32 (NO_SOURCE_FILE:1) java.lang.Thread.run (Thread.java:619)
Had anyone come across this and solved it?
Thanks