0

In Mule, how can I join applicable Product and Employee mongodb documents to each Store document in the collection or is there a better approach to retrieving information from 3 collections and populating a main JSON object in Mule?

I have three mongoDB collections:

  1. Store
  2. Product
  3. Employee

The Store collection has references to Products and Employee collections.

Using Mule I would like to:

  1. Retrieve the documents in the Store collection
  2. Retrieve all of the Products referenced by productId array field in each Store document
  3. Retrieve all of the Employees referenced by employeeId array field in each Store document

The result I am looking for is something like this:

{
    "stores": [{
        "storeId": "1234A",
        "name": "Store 1",
        "products": [{
            "productId": "ABCDEF1",
            "productName": "Phone",
            "price": 100.00
        }],
        "employees": [{
            "employeeId": "EMP1",
            "employeeName": "John",
            "dept": "sales"
        }]

    }]
}

Thanks

user3165854
  • 1,505
  • 8
  • 48
  • 100
  • maybe this link help you [$lookup on ObjectId's in an array](http://stackoverflow.com/questions/34967482/lookup-on-objectids-in-an-array) – ihsan Jan 03 '17 at 11:53
  • That's a useful document but need to find out how to do it using mule using external ids such as productId instead of _id and access other documents using references – user3165854 Jan 03 '17 at 17:49

0 Answers0