Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB insert data after find query

I'm using MongoDB with Mongochef GUI over an Ubuntu Virtual Machine. I need to do a Query which insert the data that I have found previously.

How can i do this? I thought something like this:

db.createCollection("prueba", { capped : true, size : 5242880, max : 5000 } )
db.gmap.find( { emotion: 1 } )
db.prueba.insertMany(db.gmap.find( { emotion: 1 } ))

GMAP is other collection that i have and the find query returns needed data. Thanks

like image 954
aserrin55 Avatar asked Dec 14 '25 20:12

aserrin55


1 Answers

To solve that we need to store result as an array and then insert - please find snippet below:

var a = db.sourceCollection.find().toArray()
db.destinatioCollection.insert(a)
like image 94
profesor79 Avatar answered Dec 18 '25 10:12

profesor79



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!