#81 Creating a reusable class | Using MongoDB with Express| A Complete NODE JS Course

  Рет қаралды 5,502

procademy

procademy

Күн бұрын

Пікірлер: 25
@Pareshbpatel
@Pareshbpatel Жыл бұрын
An excellent tutorial on creating a re-usable class for fetching data from MongoDB using Express. Thanks. {2023-08-23}
@taiwotopesunday
@taiwotopesunday 10 ай бұрын
@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?
@AnilKumar-pb3pc
@AnilKumar-pb3pc 3 ай бұрын
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
@anmolgarg683
@anmolgarg683 8 ай бұрын
@procademy , sir, we cannot perform the highest rated function by applying a reusable class.
@GokulKrishnan-g1n
@GokulKrishnan-g1n Жыл бұрын
this method is not working properly sir
@abdosamy8981
@abdosamy8981 Жыл бұрын
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.
@MuhsinIbrahim-mf2vw
@MuhsinIbrahim-mf2vw 7 ай бұрын
change the default sort from (-createdAt) to query = query.sort('-name');
@bishwashkumarsah171
@bishwashkumarsah171 5 ай бұрын
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
@User-sm4ld
@User-sm4ld 4 ай бұрын
But Sir what if a client is only want to use any one of these methods
@deyvisondevs5163
@deyvisondevs5163 Жыл бұрын
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
@procademy Жыл бұрын
I hope you are returning "this" instead of this.query
@deyvisondevs5163
@deyvisondevs5163 Жыл бұрын
@@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
@hardikarora1521
@hardikarora1521 Жыл бұрын
@@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
@kevinbenson9786
@kevinbenson9786 11 ай бұрын
@@procademy Even I am facing the same error like ​ @deyvisondevs5163
@husnainahmed606
@husnainahmed606 Жыл бұрын
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
@vinaykumarkharwar177
@vinaykumarkharwar177 Жыл бұрын
go to your pckage.json, inside type ---- "type":"module"
@SatwikBhatia-yf7uk
@SatwikBhatia-yf7uk 3 ай бұрын
bhai chatgpt ka naam suna h? debug k lie?
@GokulKrishnan-g1n
@GokulKrishnan-g1n Жыл бұрын
the error has came like cannot read the property of undefined i used onyl the sort method
@procademy
@procademy Жыл бұрын
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
@rishiraj2548
@rishiraj2548 Жыл бұрын
Thanks
@akhilp3826
@akhilp3826 Жыл бұрын
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
@harshdubey1637
@harshdubey1637 Жыл бұрын
thanks a lot its working
@carlossosa306
@carlossosa306 11 ай бұрын
I had the same problem, but your solution helped me, thank you very much my friend!
@muhammadkazim9420
@muhammadkazim9420 6 ай бұрын
thanks a lot, its working
@viditvaish7317
@viditvaish7317 3 ай бұрын
Thanq bhai ,its working
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
Mongoose part 3: Advanced Subdocuments and References
15:44