如何加入mongodb?

How to do join in mongodb?

我仍在努力了解 mongodb 查询的工作原理。也许这是重复的,但我找不到确切的场景。

我脑子里有这个问题

SELECT
 a.f1,
 a.f2,
 b.f1,
 b.f3 -- or select the all column of b (b.*)
FROM tableA as a
inner join tableB as b
 on(a.f1 = b.f1)
WHERE some conditions here

我能想到的最接近的解决方案是使用 $lookup,但无法做到正确。

并尝试过这样。

collectionA.aggregate({
 $lookup: {
  from: 'collectionB',
  localField: 'f1',
  foreignField: 'f1',
  as: 'b'
 }
})
// But I don't know what next here.
// I tried to combine the syntax of find query but with no avail.

请帮忙谢谢

编辑:

其实我是这样查询tableA的

tableA.find({
 $and: [{
  schedule: {
   $gte: new Date(from),
   $lte: new Date(to)
  }
 }, {
  f1: {
   $in: some values here
  }
 }]
})

我想添加来自 table 的数据。

现在可以使用了。

collectionA.aggregate([{
 $match: {
  $and: [{
   schedule: {
    $gte: new Date(from),
    $lte: new Date(to)
   }
  }, {
   f1: {
    $in: some values
   }
  }]
 }
}, {
 $lookup: {
  from: 'collectionB',
  localField: 'f1',
  foreignField: 'f1',
  as: 'b'
 }
}, {
 $project: {...}
}])

谢谢。