简体   繁体   English

Mongodb 查找比较数组元素到数组字段

[英]Mongodb find comparing array element to array field

I'm wondering how I can compare arrays of (nested) objects in Mongoose.我想知道如何比较 ZCCADCDEDB567ABAE643E15DCF0974E503Z 中(嵌套)对象的 arrays。

Considering the codebelow, I would like to get results when the pskills properties match.考虑到下面的代码,我想在 pskills 属性匹配时得到结果。 Could anyone help me with this?谁能帮我解决这个问题?

  ao = await Ao.find({
//req.body.pSkills is arraay //['nodejs', 'angular'..]
                pSkills: { $eq: req.body.pSkills }
          });

You have to use $in to search into an array.您必须使用$in来搜索数组。

Try this query:试试这个查询:

ao = await Ao.find({
  "pSkills": {
    "$in": req.body.pSkills
  }
})

Check this example检查这个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM