I'm using this lib to apply filters
I need to filter for this entity;
'use strict'
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const schema = new Schema({
id: {
type: String,
trim: true
},
name: {
type: String,
trim: true
},
description: {
type: String,
trim: true
},
restaurantId: {
type: String,
trim: true
},
price: {
type: Number,
trim: true
},
})
module.exports = mongoose.model('Menu', schema);
Through the API documentation QUERY PARAMS can create this method;
exports.list_all_dataProviders = async (req, res) => {
const { filter, skip, limit, sort, projection } = aqp(req.query);
Menus
.find(filter)
.skip(skip)
.limit(limit)
.sort(sort)
.select(projection)
.exec(async (err, result) => {
if (err) {
return res.status(500).jsonp({message:"There was an internal error listing all the providers " + err});
}
let count = await Menus.find().count()
res.status(200).jsonp({
size: limit,
page: skip,
total: count,
data: result
});
});
};
And I did the following tests on Postman;
http://localhost:3000/menu?price=14.9
http://localhost:3000/menu?price=4.9
http://localhost:3000/menu?price=6.9
And it took perfectly, but I did this test and I did not succeed;
It could not perform any filter for the description field
http://localhost:3000/menu?description=Coberto
And for the field name only managed to get the first record.
What's wrong is my method, I need to fix it.