how to join two tables in mongodb.
For example,
table 1 : users
table 2 : examples
Here users table having username and examples table also having username, so how to combine both table fields using mongodb in php.
Please explain the query.
Thanks,
Unfortunately there is no merging/joining operation directly in MongoDB. Anyway, you can use the map-and-reduce functionality in order to combine the data appropriately.
Depending on your actual problem, the following links might be of help:
MongoDB: Combine data from multiple collections into one..how?
Merging two collections in MongoDB
http://www.pal-blog.de/entwicklung/mongodb/mapreduce-multiple-mongodb-collections-into-one.html
https://groups.google.com/forum/#!topic/mongodb-user/OQUH_wxYyRg
https://groups.google.com/forum/#!topic/mongodb-user/qxa7ZBTk7sQ
I would personally recommend you stop using Map Reduce for this before you start (in reference to the other answers).
As a person who has had to do MongoDB JOINs in an actual production application I can tell you that Map Reduce is probably the worst method imaginable for this solution.
It was back in 2012 and it is now.
The only beneift you have in current versions of MongoDB is that many isolates can run concurrently instead of just one at a time (imagine single threaded JOINs across ALL connections in 2012 :\
, this was and is a terrible idea).
You want to implement this in the client side, pulling the records out all at once from the disparate collections and merging them within your application logic. That is the only real sure way to scale a JOIN in MongoDB.
There is nothing like join in mongodb
Check below answer
MongoDB: Combine data from multiple collections into one..how?