you are the only youtuber who teaching node js in detail. its amazing. thanks
@mohamedibrahemsaad5733 ай бұрын
you are the king of this platform!
@AjayCoding Жыл бұрын
Really Helpful
@ankitSingh-tu5on Жыл бұрын
Aap projects pr videos kb upload kroge?
@AjayCoding Жыл бұрын
👌
@mozammilahmad8431 Жыл бұрын
Sir plz is backend ko Angular k sath fronntend me use kijiyega.. MEAN stack project
@imanariyobaptiste8177 Жыл бұрын
I LIKE IT
@dh15693 ай бұрын
Anyone have the corrected code for this lesson. All this does is return All Movies.
@rbedson89652 ай бұрын
we can use if statement to check if sort==='-ratings' && limit==='5' and then use MovieModel.find(query).sort('-ratings).limit(5) and return the data accordingly and for normal usage, whatever we have done earlier is good enough
@harishbabus.r39579 күн бұрын
//to get the highest rated movies exports.getHighestRated = (req,res, next)=>{ //creating our own query req.query.limit = '5'; req.query.sort = '-ratings'; next(); } //1)get all movies callback exports.getAllMovies = async(req,res)=>{ //.find() method is used to query documents or get documents from mongodb try { // This approach is for mongoose version 6.0 or less // const excludeFields = ["sort", "page", "limit", "fields"]; // const queryObj = {...req.query}; // //delete the properties not required // excludeFields.forEach((el)=>{ // delete queryObj[el] // }); // let movies = await Movie.find(queryObj); //logic for more complex filters let queryStr = JSON.stringify(req.query); //converting as string queryStr = queryStr.replace(/\b(gte|gt|lte|lt)\b/g,(match)=> `$${match}`); //adding $ to query string const queryObj = JSON.parse(queryStr); //converting to JSON Object console.log(queryObj) let query = Movie.find(queryObj); let query1 = Movie.find(); //query object, we can perform query methods like sort etc //Sorting Logic if(req.query.sort){ const sortBy = req.query.sort.split(',').join(' '); //making multiple sort query with space query = query1.sort(sortBy) }else { //it should sort based created date query = query.sort("-createdAt") //descending order } //Limiting Fields(include or exclude fields) if(req.query.fields){ //query.select('name duration price ratings') const fields = req.query.fields.split(',').join(' '); query = query1.select(fields); }else { //default need to exclude __v field query.select('-__v'); //use - symbol to exclude field } //PAGINATION using .skip().limit() method const page = req.query.page*1 || 1; //converting as number and default value const limit = req.query.limit*1 ||10; //PAGE 1: 1-10; PAGE 2: 11-20; PAGE 3 : 21-30 .. const skip = (page - 1)*limit; //calculating count for skip console.log(skip) query = query1.skip(skip).limit(limit); if(req.query.page) { //to handle error const moviesCount = await Movie.countDocuments(); if(skip >= moviesCount) { throw new Error("This page is not found!"); } } let movies = await query; res.status(200).json({ status : "Success", length : movies.length, data : { movies : movies } }) }catch(err){ res.status(404).json({ status : "fail", message : err.message }) } }
@chinmayeemahapatra504 Жыл бұрын
Could you please provide source code link for node project