If I have this Schema...
maid = {
services: [{
type: String,
enum: ["cleaning", "cooking", "baby sitting"]
}]
}
- How would I write query in URL to find all maids having services "cleaning" and "cooking" only.
Example: "http://company/maids?services=cleaning,cooking" or in some other way.
- How to find all maids from database with required services?
Example:
Maid.find({
services: {
$all:req.query.services
}
})
or
Maid.find(req.query);
Please suggest some good ways to do the above.
CodePudding user response:
- Use should use
http://company/maids?services=cleaning,cooking
- Use could use this $all in mongodb like
Maid.find({services:{$all: req.query.services.split(',')}})
ps: Use have to validate the query before search