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

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 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 9 месяцев назад +2

    @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 месяца назад +1

    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

  • @GokulKrishnan-g1n
    @GokulKrishnan-g1n Год назад +4

    this method is not working properly sir

  • @anmolgarg683
    @anmolgarg683 7 месяцев назад +2

    @procademy ,
    sir, we cannot perform the highest rated function by applying a reusable class.

  • @rishiraj2548
    @rishiraj2548 Год назад

    Thanks

  • @User-sm4ld
    @User-sm4ld 3 месяца назад

    But Sir what if a client is only want to use any one of these methods

  • @deyvisondevs5163
    @deyvisondevs5163 Год назад +1

    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 Год назад +1

      @@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 10 месяцев назад

      @@procademy Even I am facing the same error like ​ @deyvisondevs5163

  • @abdosamy8981
    @abdosamy8981 Год назад +1

    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 6 месяцев назад

      change the default sort from (-createdAt) to query = query.sort('-name');

  • @bishwashkumarsah171
    @bishwashkumarsah171 4 месяца назад

    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

  • @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

  • @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

  • @akhilp3826
    @akhilp3826 Год назад +5

    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 10 месяцев назад

      I had the same problem, but your solution helped me, thank you very much my friend!

    • @muhammadkazim9420
      @muhammadkazim9420 5 месяцев назад

      thanks a lot, its working

    • @viditvaish7317
      @viditvaish7317 2 месяца назад

      Thanq bhai ,its working