How to merge two colletion in MongoDB of same type using single Query -


this question has answer here:

i have 2 collections a , b , both having document below :

collection a

{_id:id1  name: mohan  age:25 } 

collection b

{_id:id2  name: sohan  age:29 } 

i want merge 2 collection a , b , expected output below:

{_id:id1,  name: mohan,  age:25}, {_id:id2,  name: sohan  age:29 } 

any 1 knows how merge 2 collections? , don't want create new collection.

if want add documents of collection1 collection2 need use foreach function given below :

db.collection1.find().foreach(function(doc){db.collection2.save(doc)}); 

the collection2 contains document collection1 of own documents.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -