无法通过 mongodb 中的过滤器 () 获取数据

Can't get data via filter () in mongodb

我正在尝试通过此查找分配给用户的任务

router.get('/all', auth, async (req, res) => {
  try {
    const assignments_raw = await Assignment.find({listP: listP.indexOf(req.user.userId)})
    res.json(assignments_raw)
  } catch (e) {
    res.status(500).json({ message: 'Something went wrong, try again' })
  }
})

具体来说,这一行应该已经找到了在 listP 字段中具有与用户 ID 对应的元素的所有任务

 const assignments_raw = await Assignment.find({listP: listP.indexOf(req.user.userId)})

但这会导致错误,为什么? 以下是芒果的摘录

你可以这样做

router.get('/all', auth, async (req, res) => {
  try {
    const assignments_raw = await Assignment.find()
    let assignments = []
    assignments_raw.map(assignment => {
          if (assignment.listP.indexOf(req.user.userId) !== -1) {
              assignments.push(assignment)
          }


        }
        )
    res.json(assignments)
  } catch (e) {
    res.status(500).json({ message: 'Something went wrong, try again' })
  }
})