Insert all documents from one collection into another collection in MongoDB database -


i have python script collects data everyday , inserts mongodb collection (~10m documents). job fails , left partial data not useful me. insert data staging collection first , copy or move documents staging collection final collection when job finishes , data complete. cannot seem find straight forward solution doing "bulk" type operation, seems there should one.

in sql this:

insert final_table select * staging_table 

i thought db.collection.copyto() work seems makes destination collection clone of source collection.

additionally, know this: mongodb move documents 1 collection collection can following:

var documentstomove = db.collectiona.find({}); documentstomove.foreach(function(doc) {     db.collectionb.insert(doc); } 

but seems there should more efficient way.

so, how can take documents 1 collection , insert them collection in efficient manner?

note: final collection has data in already. new documents want move on adding data, e.g if staging collection has 2 documents , final collection has 10 documents, have 12 documents in final collection after move staging data over.

you can use db.clonecollection(); see mondb clonecollection


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -