2

I am trying to use mongo 3.4 $lookup:function

db.orders.aggregate([
    {
      $lookup:
        {
          from: "inventory",
          localField: "item",
          foreignField: "sku",
          as: "inventory_docs"
        }
   }
])

orders:
{ "_id" : 1, "itemid" : "1234", "price" : 12, "quantity" : 2 }

invdentory :
{ "_id" : 1, "skuid" : 123, description: "product 1", "instock" : 120 }

The problem here is the fields to be joined are of string and integer. How can i make this lookup possible in mongo

Awknewbie
  • 269
  • 4
  • 15

1 Answers1

2

It's not possible to change the datatype inside the $lookup step of the aggregation pipeline. The topic has already been discussed here:

In both threads the final solution was: you must previously convert the datatype programmatically

Davis Molinari
  • 741
  • 1
  • 5
  • 20