Problem with query mongoose nodejs

hello, I am developing a site to follow a payment tutorial with nodejs mongoose.

Hello. I created a login page that allows the user to login to take a video tutorial that I sell to them when they log in.

After the payment was successful, I registered the user in a new model called payment.
From that point
I want to display the link to follow the tutorial as soon as it connects.
Now if he hasn’t purchased the button yet, thank you

USER SESSION PAGE

 <%  if(docs)   {%>
          <button class="btn btn-info my-2 my-sm-0 m-3">
            <a class="nav-link text-white " href="/tutorial">
            Access aux Cours
            </a>
        </button>
       <% } else {%>
        <section class="py-2">
          <div class="row">
          <div class="col-md-6 text-center">
      
            <button id="checkout-button" type="submit" class="btn btn-outline-dark text-white btn-lg">acheter maintenant</button>
              <script type="text/javascript">
                // Create an instance of the Stripe object with your publishable API key
                var stripe = Stripe(secret);
               var checkoutButton = document.getElementById('checkout-button');
          
                if(checkoutButton){
                  checkoutButton.addEventListener('click', function() {
                  // Create a new Checkout Session using the server-side endpoint you
                  // created in step 3.
                  fetch('/charge', {
                    method: 'POST',
                  })
                  .then(function(response) {
                    return response.json();
                  })
                  .then(function(session) {
                    return stripe.redirectToCheckout({ sessionId: session.id });
                  })
                  .then(function(result) {
                    // If `redirectToCheckout` fails due to a browser or network
                    // error, you should display the localized error message to your
                    // customer using `error.message`.
                    if (result.error) {
                      alert(result.error.message);
                    }
                  })
                  .catch(function(error) {
                    console.error('Error:', error);
                  });
                });
  
                }
              
              </script>
          </div>
         
        </div>
      </section>

       <%}  %>
      

CONTROLLERS


const User = require('../models/users')
const Payment = require('../models/payment')

const getSchool = async (req, res) =>{
    let {name, id, email} = req.user
    res.render('compte', {
        name: name,
        id: id

    })

    Payment.find( (err, docs) =>{
        console.log('test: ', id);
        console.dir(docs);
        if(err) console.log(err);
        res.render('compte', {docs: docs})
    })

}


const postCharge = async (req, res) =>{
    let {email, id, name} = req.user
    const savePayment = new Payment({
         Userid: id,
         name: name,
         email: email,

         
     })

    savePayment.save((err, userPayment) =>{
        if(err) console.log(err);
    })



    const session = await stripe.checkout.sessions.create({
        customer_email:  email,
        payment_method_types: ["card"],
        line_items: [
          {
            price_data: {
              currency: "eur",
              product_data: {
                name: "tutorial",
              },
              unit_amount: 2000,
            },
            quantity: 1,
          },
        ],
        mode: "payment",
        success_url: "https://example.com/success",
        cancel_url: "https://example.com/cancel",
      });
      res.json({ id: session.id });
 
}

const getPass = (req, res) =>{
   res.render('tutorial')


}

RESULT IN TERMINAL

ReferenceError: D:\Node js\papeGeuye\views\compte.ejs:40
   38|
   39|
>> 40|         <%  if(docs)   {%>
   41|           <button class="btn btn-info my-2 my-sm-0 m-3">
   42|             <a class="nav-link text-white " href="/tutorial">
   43|             Access aux Cours

docs is not defined
   at eval (eval at compile (D:\Node js\papeGeuye\node_modules\ejs\lib\ejs.js:661:12), <anonymous>:21:9)
   at compte (D:\Node js\papeGeuye\node_modules\ejs\lib\ejs.js:691:17)
   at tryHandleCache (D:\Node js\papeGeuye\node_modules\ejs\lib\ejs.js:272:36)
   at View.exports.renderFile [as engine] (D:\Node js\papeGeuye\node_modules\ejs\lib\ejs.js:489:10)
   at View.render (D:\Node js\papeGeuye\node_modules\express\lib\view.js:135:8)
   at tryRender (D:\Node js\papeGeuye\node_modules\express\lib\application.js:640:10)
   at Function.render (D:\Node js\papeGeuye\node_modules\express\lib\application.js:592:3)
   at ServerResponse.render (D:\Node js\papeGeuye\node_modules\express\lib\response.js:1012:7)
   at getSchool (D:\Node js\papeGeuye\controllers\user.js:113:9)
   at Layer.handle [as handle_request] (D:\Node js\papeGeuye\node_modules\express\lib\router\layer.js:95:5)
   at next (D:\Node js\papeGeuye\node_modules\express\lib\router\route.js:137:13)
   at ensureAuthenticated (D:\Node js\papeGeuye\config\auth.js:4:16)
   at Layer.handle [as handle_request] (D:\Node js\papeGeuye\node_modules\express\lib\router\layer.js:95:5)
   at next (D:\Node js\papeGeuye\node_modules\express\lib\router\route.js:137:13)
   at Route.dispatch (D:\Node js\papeGeuye\node_modules\express\lib\router\route.js:112:3)
   at Layer.handle [as handle_request] (D:\Node js\papeGeuye\node_modules\express\lib\router\layer.js:95:5)

events.js:200
     throw er; // Unhandled 'error' event
     ^

TypeError: req.next is not a function
   at done (D:\Node js\papeGeuye\node_modules\express\lib\response.js:1007:25)
   at tryRender (D:\Node js\papeGeuye\node_modules\express\lib\application.js:642:5)
   at Function.render (D:\Node js\papeGeuye\node_modules\express\lib\application.js:592:3)
   at ServerResponse.render (D:\Node js\papeGeuye\node_modules\express\lib\response.js:1012:7)
   at D:\Node js\papeGeuye\controllers\user.js:123:13
   at D:\Node js\papeGeuye\node_modules\mongoose\lib\model.js:4838:16
   at D:\Node js\papeGeuye\node_modules\mongoose\lib\model.js:4838:16
   at D:\Node js\papeGeuye\node_modules\mongoose\lib\helpers\promiseOrCallback.js:24:16
   at D:\Node js\papeGeuye\node_modules\mongoose\lib\model.js:4861:21
   at D:\Node js\papeGeuye\node_modules\mongoose\lib\query.js:4406:11
   at D:\Node js\papeGeuye\node_modules\kareem\index.js:135:16
   at processTicksAndRejections (internal/process/task_queues.js:76:11)
Emitted 'error' event on Function instance at:
   at D:\Node js\papeGeuye\node_modules\mongoose\lib\model.js:4840:13
   at D:\Node js\papeGeuye\node_modules\mongoose\lib\helpers\promiseOrCallback.js:24:16
   [... lines matching original stack trace ...]
   at processTicksAndRejections (internal/process/task_queues.js:76:11)

Hey there,

would be great to see your whole code, not only some parts! :+1:

Did you install ejs?
Did you add it to the express app as engine?

of course I have it in my app.js

ok

const mongoose = require('mongoose')

const userSchema = new mongoose.Schema({
    Userid: {
        type: String,
        require: true
    },
    name: {
        type: String,
        require: true
    },
    email: {
        type: String,
        require: true
    }
})

const Payment =  mongoose.model('Payment', userSchema)

module.exports = Payment
const mongoose = require('mongoose')

const newSchma = new mongoose.Schema({
    name:{
     type: String, 
     require: true
    },
    email:{
        type: String, 
        require: true
    },

    password:{
        type: String, 
        require: true
    },
  
    date:{
        type: Date,
        default: Date.now
    }
})

const user = mongoose.model('user', newSchma)
module.exports = user

MY server.js

const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const flash = require('connect-flash')
const session = require('express-session')
const passport = require('passport')
const app = express()
const port = 3000

require('./config/passport')(passport)

//MONGOOSE
mongoose.connect('mongodb://localhost/Gueyelogin', {useNewUrlParser: true, useUnifiedTopology: true});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
   console.log('mon db marche bien !!');
});

//BODY-PARSER
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())


// EJS
app.set('view engine', 'ejs')

app.use('/public', express.static('public'));

//SESSION 
app.use(session({
    secret: 'secret',
    resave: true,
    saveUninitialized: true,
  }))

//Passport middleware
app.use(passport.initialize());
app.use(passport.session());

//CONNECT-FLASH
app.use(flash())


//GLOBALS VARS
app.use((req, res, next) =>{
    res.locals.success_msg = req.flash('success_msg')
    res.locals.error_msg = req.flash('error_msg')
    res.locals.error = req.flash('error')
    next()
})

// ROUTE
const indexRouter = require('./routes/index')
app.use('/', indexRouter)


app.listen(port, () =>{
    console.log('mon port marche bien ', port);
})

MY CONTRLLOERS

const User = require('../models/users')
const Payment = require('../models/payment')
const bcrypt = require('bcryptjs')
const passport = require('passport')
const { resolve } = require("path");
const { get } = require('http');
const stripe = require("stripe")('sk_test_51HQC7ALo5RtUv286nakexNANwWYSgVhspxWUBGsZDVzPsv8pZ48SWUPu5j86CFYSLRVCYgr2Ye90IvRME6Vpja4c00TDwv1Ns3')




const getRegister = (req, res) =>{
    res.render('register')
}

const postRegister = (req, res) =>{
   // console.log(req.body);

    const {name, email, password, password2} = req.body
    let errors = []

    if(!name || !email || !password || !password2){
        errors.push({msg: 'Merci de  remplir tous les champs'})
    }

    if(name < 6){
        errors.push({msg: 'Votre nom et prenom ne sont pas valide'})
    }
    if(password != password2){
        errors.push({msg: 'les deux mot de passe ne sont pas identique'})
    }
    if(password.length < 6){
        errors.push({msg: 'le mot de passe doit contenir 6 caractere'})
    }

    if(errors.length > 0){
        res.render('register', {
            errors,
            name,
            email,
            password,
            password2
        })
 
    } else{
       User.findOne({email: email})
       .then(user =>{
           if(user){
               errors.push({msg: "l'email existe déja"})
               res.render('register', {
                 errors,
                 name,
                 email,
                 password,
                 password2
             })
 
         } else{
            const userSave = new User({
                name: name,
                email: email,
                password: password
            })
 
            //CACHE LE MOT DE MOT PASS 
            bcrypt.genSalt(10, (err, salt) =>{
            bcrypt.hash(userSave.password, salt, (err, hash) =>{
                if(err) throw err
                userSave.password = hash
 
                //save User model
 
                userSave.save((err, user) =>{
                    if(err) throw err
                    req.flash('success_msg', 'Vous êtes maintenant enregistrer')
                    res.redirect('/login')
                })
            })
         });
 
         }
       })
    }
}


 const getLogin = (req, res) =>{
  res.render('login')
 }

   const postLogin = (req, res, next) =>{
     passport.authenticate('local', {
    failureRedirect: '/login',
     successRedirect: '/tutorial&JURISPRUDENCE',
     failureFlash: true

   })(req, res, next)
}





const logout = (req, res) =>{
    req.logout();
    req.flash('success_msg', 'Vous êtes déconnectés')
    res.redirect('/login')
}


const getSchool = async (req, res) =>{
    let {name, id, email} = req.user
    res.render('compte', {
        name: name,
        id: id

    })
  Payment.find( (err, docs) =>{
        console.log('test: ', id);
        console.dir(docs);
        if(err) console.log(err);
        res.render('compte', {docs: docs})
    })

}
 


 
 

}


const postCharge = async (req, res) =>{
    let {email, id, name} = req.user
    const savePayment = new Payment({
         Userid: id,
         name: name,
         email: email,

         
     })

    savePayment.save((err, userPayment) =>{
        if(err) console.log(err);
    })



    const session = await stripe.checkout.sessions.create({
        customer_email:  email,
        payment_method_types: ["card"],
        line_items: [
          {
            price_data: {
              currency: "eur",
              product_data: {
                name: "tutorial",
              },
              unit_amount: 2000,
            },
            quantity: 1,
          },
        ],
        mode: "payment",
        success_url: "https://example.com/success",
        cancel_url: "https://example.com/cancel",
      });
      res.json({ id: session.id });
 
}

const getPass = (req, res) =>{
   res.render('tutorial')


}
 

module.exports = {
    getRegister: getRegister,
    postRegister: postRegister,
     getSchool: getSchool,
    getLogin: getLogin,
    postLogin: postLogin,
    logout: logout,
    postCharge: postCharge,
    getPass: getPass
}