如何在 URL 中设置查询以及如何在 mongoose 中通过字符串数组查找对象?

How to set query in URL and how to find Objects by an array of Strings in mongoose?

如果我有这个架构...

maid = {
    services: [{
        type: String,
        enum: ["cleaning", "cooking", "baby sitting"]
    }]
}
  1. 我如何在 URL 中编写查询以查找所有仅提供“清洁”和“烹饪”服务的女佣。

示例:“http://company/maids?services=cleaning,cooking”或其他方式。

  1. 如何从数据库中找到所有需要服务的女佣?
    示例:
Maid.find({
    services: {
        $all:req.query.services
    }
}) 

Maid.find(req.query);

请提出一些完成上述操作的好方法。

  1. 使用应该使用http://company/maids?services=cleaning,cooking
  2. 用户可以像 Maid.find({services:{$all: req.query.services.split(',')}})
  3. 那样在 mongodb 中使用这个 $all

ps: 使用 have to validate the query before search