Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-8930

lookup between local (multiple)array of values and foreign (single) value

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • Server_Docs_20231030
    • Affects Version/s: None
    • Component/s: Server
    • Labels:
      None

      Example Order Document:

      {
          _id: ObjectId("..."),
          products: [ ObjectId("..<Car ObjectId>.."), ObjectId("..<Bike ObjectId>..") ]
      }
      

      Not Working Query:

      db.orders.aggregate([ {
          $lookup: {
                 from: "products",
                 localField: "products",    <= array of IDs
                 foreignField: "_id",
                 as: "productObjects"
          }
      } ])
      

      Desired Result

      {
        _id: ObjectId("..."),
        products: [
          ObjectId("..<Car ObjectId>.."),
          ObjectId("..<Bike ObjectId>..")
        ],
        productObjects: [
          {<Car Object>},
          {<Bike Object>}
        ],
      }
      

      source: http://stackoverflow.com/questions/34967482/lookup-on-objectids-in-an-array

            Assignee:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Reporter:
            emily.hall Emily Hall
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              7 years, 31 weeks ago