In this post, we'll see how to install MongoDB support for Pig and we'll illustrate it with an example where we join 2 MongoDB collections with Pig and store the result in a new collection.
Download Hadoop 1.1.1 from http://www.apache.org/dyn/closer.cgi/hadoop/common/. Set your PATH to the bin directory in Hadoop.
Download the latest Mongo Java driver from https://github.com/mongodb/mongo-java-driver/downloads and put it in your directory ~/pig_libraries.
We're going to use the GIT project developed by 10gen but with a slightly modification that we made. Because the Pig language doesn't support variable that starts with underscore (e.g., _id) which is used in MongoDB, we added the ability to use it by replacing the _ prefix with u__ so _id becomes u__id.
One of the thing you can't do in MongoDB is to do a join between 2 collections. So let's see how we can do it simply with a pig script.
and let's create a new collection person_department that will give for each person the name of the department (s)he is in.
Voila! you just did a join with Pig and MongoDB!
KratiJain did you find the solution? I am stuck on the same problem for a while.