0

I have two collection as bellow products has reference of user. i search product by name & in return i want combine output of product and user using map reduce method

user collection
{
  "_id" : ObjectId("52ac5dd1fb670c2007000000"),
  "company" : {
    "about" : "This is textile machinery dealer",
    "contactAddress" : [{
        "address" : "abcd",
        "city" : "52ac4bc6fb670c1007000000",
        "zipcode" : "39as46as80"
      },{
        "address" : "abcd",
        "city" : "52ac4bc6fb670c1007000000",
        "zipcode" : "39as46as80"
      }],
    "fax" : "58784868",
    "mainProducts" : "ads,asd,asd",
    "mobileNumber" : "9537236588",
    "name" : "krishna steels",
    }
  "user" : ObjectId("52ac4eb7fb670c0c07000000")
}

product colletion
{
  "_id" : ObjectId("52ac5722fb670cf806000002"),
  "category" : "52a2a9cc48a508b80e00001d",
  "deliveryTime" : "10 days after received the ",
  "price" : {
    "minPrice" : "2000",
    "maxPrice" : "3000",
    "perUnit" : "5288ac6f7c104203e0976851",
    "currency" : "INR"
  },
  "productName" : "New Mobile Solar Charger with Carabiner",
  "rejectReason" : "",
  "status" : 1,
  "user" : ObjectId("52ac4eb7fb670c0c07000000")
}

2 Answers2

0

This cannot be done. Mongo support Map Reduce only on one collection. You could try to fetch and merge in a java collection. Couple of days back I solved a similar problem using java collection.

Click to see similar response about joins and multi collection not supported in mongo.

Community
  • 1
  • 1
java_dude
  • 4,038
  • 9
  • 36
  • 61
0

This can be done using two map reduces.

You run your first MR and then you reduce out the second MR onto the results of the first.

You shouldn't do this though. JOINs are not designed to be done through MR, in fact it sounds like you are trying to do this MR with inline output which in itself is a very bad idea.

MRs are not designed to run inline to the application.

You would be better off doing the JOIN else where.

Sammaye
  • 43,242
  • 7
  • 104
  • 146