db.getCollection('experiment_scopes').aggregate( [ { $match: {_id: "c42_v[5-42]_1"} }, { $unwind: "$instances" }, { $project: {"instance_id": "$instances"} }, { $lookup: { from: "wmis_qubos", localField: "instance_id", foreignField: "instance", as: "wmis_qubo" } }, { $unwind: "$wmis_qubo" }, { $project: { instance_id: true, wmis_qubo_id: "$wmis_qubo._id" } }, { $lookup: { from: "embeddings", let: { qubo_id: "$wmis_qubo_id", solver_graph_id: ObjectId("5c9e13168c6fe628c16eb361") }, pipeline: [ { $project: { qubo: true, solver_graph: true, } }, { $match: { $expr: { $and: [ {$eq: ["$qubo", "$$qubo_id"]}, {$eq: ["$solver_graph", "$$solver_graph_id"]} ] } } }, { $project: { _id: true } } ], as: "embeddings_id" } }, { $unwind: "$embeddings_id" }, { $project: { instance_id: true, wmis_qubo_id: true, embeddings_id: "$embeddings_id._id" } } ])