SQL >> Database teknologi >  >> NoSQL >> MongoDB

Brug $lookup med nested arrays

Unwind nested arrays før $lookup, så localField kan matches korrekt.

db.personaddress.aggregate([{ $unwind: "$address" }, { $unwind: "$address.location" }, { $lookup: { from: "places", localField: "address.location.place._id", foreignField: "_id", as: "place" } }]);
  1. Tæl distinkte værdier med MongoDB-aggregation

  2. Brug $lookup med pipeline i Spring Data MongoDB

  3. Ret sortering i MongoDB Aggregation Pipeline

  4. Kør MongoDB-aggregationer i en LoopBack-app