I have updated this blog . As last description was creating some misunderstanding and lot of confusion .
In one of my project , there was a requirement to generate report in .csv format from MongoDB without using any reporting tool and any language .
I had to use only MongoDB query .
In that report , I had to use multiple collection . Since there was not a well structured DB schema .
We are using MongoDB , which is non -relational database . Despite of this fact , there were related collections .
As we know MongoDB is a no-SQL database and doesn’t support joins. But I found an alternate to implement JOINs in MongoDb using Map Reduce.
For Versions below Mongo 2.4:-
Let’s go with a small example :
We have two collections Employee and Department . We have to fetch details of all employees with their department .
1) Create Employee and Department collection .
4) MongoDB provides mapReduce commmand for Map Reduce operation .
5) ’emp_dept’ is new resulted collection where result will be stored . The Result will be :
For Version Mongo 2.4:-