@proacademy, Your contents are superb. Thank you so much. The error handling part of the paginate in the class was not handled. I have tried fixing this yet to find my way around it. How can this be handled please?
Hai Sir, Replay me please as I am using mongoose version 8.5.3 but when i am giving request other than advance filter conditions getting an empty array
Hello friend, I'm using the approach proposed in the video. At first I can use the filter method of the Feature Api class, but when I insert other queries such as sort or fields or page, the response returns an empty array. I don't get results with the sort, limitFields and paginate methods. Could you tell me what could be going on? And again, thank you very much. This course is helping me a lot in this learning journey. Great Job
@@procademy Yes, I am returning this. What happens is that if I take req.query and pass it directly as a parameter to Movie.find or as a parameter to the constructor, the find methods don't work as they should. To be able to use the methods, I needed to validate the data coming in req.query, and only then use them. I'm using mongo in the latest LTS version and mongoose in version 7.0.2
@@deyvisondevs5163 well I was getting the same problem the fault lies in queryObj we are passing in filter() method's query object what it essentially do is a filtered search based on anything after '?' in the url so if you give something like ?sort=name the 'sort' is passed in queryObj and then to query object and as there is no 'sort' field in moviesSchema it returns an empty array. so I avoided filter method chaining and everything else works just fine
Sir, There is a problem with pagination when I call page 1 and page 2 with same limit it gives the same result but in page 3 upwards it gives different results, Is there any problem with pagination? Some movies never appear in pagination.
I have a doubt why this.query = this.query.find(querystring). Why don't we use async here this.query = async this.query.find(querystring). Or why dont we use this.query = Movies.find(querystring) 8:20
An excellent tutorial on creating a re-usable class for fetching data from MongoDB using Express. Thanks.
{2023-08-23}
@proacademy,
Your contents are superb. Thank you so much.
The error handling part of the paginate in the class was not handled. I have tried fixing this yet to find my way around it. How can this be handled please?
Hai Sir, Replay me please as I am using mongoose version 8.5.3 but when i am giving request other than advance filter conditions getting an empty array
this method is not working properly sir
@procademy ,
sir, we cannot perform the highest rated function by applying a reusable class.
Thanks
But Sir what if a client is only want to use any one of these methods
Hello friend, I'm using the approach proposed in the video. At first I can use the filter method of the Feature Api class, but when I insert other queries such as sort or fields or page, the response returns an empty array. I don't get results with the sort, limitFields and paginate methods. Could you tell me what could be going on?
And again, thank you very much. This course is helping me a lot in this learning journey. Great Job
I hope you are returning "this" instead of this.query
@@procademy Yes, I am returning this. What happens is that if I take req.query and pass it directly as a parameter to Movie.find or as a parameter to the constructor, the find methods don't work as they should. To be able to use the methods, I needed to validate the data coming in req.query, and only then use them. I'm using mongo in the latest LTS version and mongoose in version 7.0.2
@@deyvisondevs5163 well I was getting the same problem the fault lies in queryObj we are passing in filter() method's query object what it essentially do is a filtered search based on anything after '?' in the url so if you give something like ?sort=name the 'sort' is passed in queryObj and then to query object and as there is no 'sort' field in moviesSchema it returns an empty array. so I avoided filter method chaining and everything else works just fine
@@procademy Even I am facing the same error like @deyvisondevs5163
Sir, There is a problem with pagination when I call page 1 and page 2 with same limit it gives the same result but in page 3 upwards it gives different results, Is there any problem with pagination? Some movies never appear in pagination.
change the default sort from (-createdAt) to query = query.sort('-name');
I have a doubt why this.query = this.query.find(querystring). Why don't we use async here this.query = async this.query.find(querystring). Or why dont we use this.query = Movies.find(querystring) 8:20
it can not getting the module function and this error occured
File is a CommonJS module; it may be converted to an ES module.
So what i can do
go to your pckage.json, inside type ----
"type":"module"
bhai chatgpt ka naam suna h? debug k lie?
the error has came like cannot read the property of undefined i used onyl the sort method
In the filter lecture, i have mentioned two ways to do it. One is for older mongoose version. Please try that approach and see if it works
filter() {
const queryCopy = {...this.queryStr};
// Removing fields from the query
const removeFields = ['sort', 'fields', 'q', 'limit', 'page'];
removeFields.forEach(el => delete queryCopy[el]);
// Advance filter using: lt, lte, gt, gte
let queryStr = JSON.stringify(queryCopy);
queryStr = queryStr.replace(/\b(gt|gte|lt|lte|in)\b/g, match => `$${match}`)
this.query = this.query.find(JSON.parse(queryStr));
return this;
}
try this might be work
thanks a lot its working
I had the same problem, but your solution helped me, thank you very much my friend!
thanks a lot, its working
Thanq bhai ,its working