0
I am using this lib to apply filters
I need to perform the 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 lib documentation API 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 took the following test at the Postman;
http://localhost:3000/menu?price=14.9
http://localhost:3000/menu?price=4.9
http://localhost:3000/menu?price=6.9
And it stuck perfectly, but I took this test and I didn’t succeed;
It failed to perform any filter for the Description field
http://localhost:3000/menu?description=Coberto
And for the name field only managed to get the first record.
What’s wrong is my method, I need to correct.
It seems strange to talk "lib API ...", usually use one or the other
– Costamilam
And which lib is used for my case?
– wladyband
That’s not what I meant... lib is nickname for library which is, in English, library, which is "a real implementation of the rules", already API, "It’s the way your code relates to a library". It is unusual to use both terms together (not necessarily wrong). Difference between the terms
– Costamilam
@Guilhermecostamilam Thanks for clarifying, but in the end you have any suggestions to help me in my problem according to the posting? Please.
– wladyband