0

i've fetch data of single model from the database but i'm getting problem while fetching multiple model from the database. while fetching model everything related to model comes in return but i want only id and datas this is my code


router.get('/',(req,res) =>{
    const how = Howitworks.find().lean();
    const value = Slider.find().lean();
    console.log(how)
    res.render('index', {how: how, value: value});
})

this is my code for fetching single model

router.get('/',(req,res) =>{
    
    Howitworks.find((err,docs)=>{
        
        if(!err){
            
            res.render("index",{
                list:docs

            })
        }
        else {
            console.log("error in retriving hoiw it works list: "+err)
        }
    }).lean()
})

is there any way to fetch both model?

1
  • show you data from mongoose please. Commented Apr 9, 2021 at 5:47

1 Answer 1

1

Hi As I understood your code, your script should be like below.

router.get('/', async(req,res) =>{
    const how = await Howitworks.find().lean();
    const value = await Slider.find().lean();
    //  You can process how, values here and use then
    console.log(how)
    res.render('index', {how: how, value: value});
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.