Friday 14 April 2017

How to display specific query items depending on form input from a webpage

I am trying to query specific items in the database, "number" and "date", and print them to the page. Both these items are being queried from one form on my webpage and I am having an issue displaying them.

var messages = mongoose.model('messages', {});

router.post('/query', function(req, res, next) {
  var query1 = req.body.dateQuery;

  messages.find({date:query1}, function(err, messages) {
     res.render('query', {messages:messages});
  });
  messages.find({number:query1}, function(err, messages) {
     res.render('query', {messages:messages});
  });
});

I have tried several different ways, but unfortunately they have not worked. I have tried putting "res.render" in both "message.find" methods(displayed above), obviously they emitted the common error involved in using 2 or more "res.xxxx()" used in a single function. How do I enable both {date:query1} and {number:query1} to be displayed to the page? I don't want them displaying all at once, I want them to display according to the input sent in from the form "query1."

Thanks! I will appreciate any tips and/or pointers you guys have!



via ItsMeRileyP

No comments:

Post a Comment