We are trying to find the collection in mongodb using parameter like following

  var student = express.Router();
  app.use('/student', student);
    student.get('/get/:sr_no/:title/:topic_title', function (req, res) 
   {
     var v1,v2,v3;
     v1=req.params['sr_no']; 
     v2=req.params['title']; 
     v3=req.params['topic_title']; 
       var cursor = dbo.collection("chepters").find({"sr_no":v1}).toArray(function(err, result) 
       {
         
         console.log(result);
            res.send(result);
       });


  })

We are trying to find the collection in mongodb using parameter like following

var student = express.Router();
app.use(’/student’, student);
student.get(’/get/:sr_no/:title/:topic_title’, function (req, res)
{
var v1,v2,v3;
v1=req.params[‘sr_no’];
v2=req.params[‘title’];
v3=req.params[‘topic_title’];
var cursor = dbo.collection(“chepters”).find({“sr_no”:v1}).toArray(function(err, result)
{

     console.log(result);
        res.send(result);
   });

})

but the variable v1 is not wokring instead if we put static value 1 in place of v1 the query is working. How to pass value as variable.

We want solution we are beginners in mongodb and node.js

Help us to find the solution.

Hi @Papu_Chopda and welcome in the MongoDB Community :muscle: !

Check out my old repo on Github here.

A few things changed I guess since 2016 but I had parameters so it’s probably about the same syntax.

If you are starting with MongoDB and Node.js, I would recommend you checkout our tutorials on the DevHub or the M220JS course on MongoDB University. Everything is free.

Cheers,
Maxime.