I'm using Monger to connect to Mongo. I want to run
db.collection.find().forEach(function(x) { db.collection-two.insert(...) })
I can't see a relevant 'for each' entry in the Monger docs or a way to pass in JavaScript to insert into another collection. How do I do this?
EDIT this question was based on a misunderstanding (forEach lies in the client API not on the server API). I would delete it but I can't.
You can process each document as a lazy sequence of Clojure maps:
Why are you trying to use JavaScript? Are you using ClojureScript, or are you just thinking in terms of how you would write code from the mongodb shell?
Disclaimer: Using
doseqhere is not functional, and probably not idiomatic depending on what you are trying to accomplish. Usingmaporreduceis probably better, I was just trying to write something that most closely aligned with yourforEachexample code.Related: