Tuesday, 18 April 2017

Find Data from adding dynamic collection name in mongoose

I want to pass collection name in req.body and query the collection with that name.I tried this but its not working in mongoose

router.get('/data',(req,res)=>{
var mySchema="User"; // i will get it from req.body.model
    mySchema.find({},(err,docs)=>{
        if(err) throw err;
        res.json({
            success:true,
            data:docs
        });
    }); 
});



via Gaurav Umrani

No comments:

Post a Comment