Get “data from collection b not in collection a” in a MongoDB shell query

In mongo 3.2 the following code seems to work

db.collectionb.aggregate([
  {
    $lookup: {
        from: "collectiona",
        localField: "collectionb_fk",
        foreignField: "collectiona_fk",
        as: "matched_docs"
      }
   },
   {
      $match: {
        "matched_docs": { $eq: [] }
      }
   }
]);

based on this https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/#use-lookup-with-an-array example

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)