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

[Server] Add multiple $lookup example

      It is possible to perform multiple $lookups in a single query, on the same collection, on fields that are derived using $addFields. A suggestion was made in a case that perhaps our documentation could be updated to indicate this. For example a query like this is possible:

      {$match: {id: {$in: [/^123456/ ,
      /^123457/
      ]}}},
      {"$addFields":{
      "BlockKey": {$concat: [ "L", { $substr: [ "$id", 0, 7 ]}] },
      "CodeKey": {$concat: [ "L", { $substr: [ "$_id", 0, 6 ]},"A"] }
      }},
      { $lookup: {
      from: "port_ss_col",
      localField: "BlockKey",
      foreignField: "_id",
      as: "BlockArray"
      }},
      { $lookup: {
      from: "port_ss_col",
      localField: "CodeKey",
      foreignField: "_id",
      as: "CodeArray"
      }},
      { $project: {...

       

      If that's not possible (or if this doc-addition doesn't make sense), that's fine; it's understood that every query use case cannot be included in our documentation. This was just a suggestion that we received.

            Assignee:
            Unassigned Unassigned
            Reporter:
            harshad.dhavale@mongodb.com Harshad Dhavale
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              1 year, 12 weeks, 6 days ago