S Viswanathan
S Viswanathan

Reputation: 47

How to join two collections in mongo Db?

I've created two collections one for people details and another for their income, spending amount etc.

i want cumulative result how to combine both collections??

Upvotes: 0

Views: 1860

Answers (2)

twg
twg

Reputation: 1105

Instead of combining them into one collection (which may or may not be correct in your situation - no way of knowing) take a look at this StackOverflow. Also you should seriously study both the lookup and aggregation possibilities in MongoDB. Since Mongo is NoSQL the way we approach lookup information is a bit different.

Upvotes: 0

Joseph Milane
Joseph Milane

Reputation: 194

You can insert all documents from one collection into another. Here is how to do that using the mongo shell:

db.collection1.find().forEach( function(x){db.collection2.insert(x)} );

Upvotes: 2

Related Questions