I'm working on a simple web service in node.js. I'm using choreographer to route the http calls. This code works fine:
router.get('/search/*', function(req, res, term){
res.writeHead(200, {'Content Type:':'text/plain'});
db.collection('foo').find({'a':1}).toArray(function(err, items){
console.log(items);
res.write(JSON.stringify(items));
res.end();
});
});
As you can see, the find method looks for {'a':1}, this works fine, a record is returned. But when I want to pass the search term from the router to the query I get a null response:
router.get('/search/*', function(req, res, term){
res.writeHead(200, {'Content Type:':'text/plain'});
db.collection('foo').find({'a':term}).toArray(function(err, items){
console.log(items);
res.write(JSON.stringify(items));
res.end();
});
});
Any ideas anyone??
Edit: I have checked the value of term, as suggested below in the comments, it is 1, which is what I expected it to be.
itemswill be null. It's good to always check.