How can I search in mongoose according to my query parameters?
<p>I have a form that user can choose to search for transaction by specifying the buyer name or item name or both .. so I can have any of these queries : </p>

<blockquote>
  <p>localhost:8000/allPayments/?i=pasta<br>
  localhost:8000/allPayments/?b=Youssef<br>
  localhost:8000/allPayments/?b=Youssef&amp;i=pasta</p>
</blockquote>

<p>In the following  code mongoose will always look for both of them</p>

<pre><code> router.get('/allPayments', function (req, res, next) {
 Transaction.find({'buyerName':req.query.b , 'itemName':req.query.i})
                            .then(function (docsPay) {
                                res.render('allPayments', {
                                    payments: docsPay 
                  });
 });
</code></pre>

<p>How can I tell mongoose to only look for what is passed in the query without writing the above code 3 different times ?
For example : only do find({'buyerName':req.query.b}) if the query is the 2nd one </p>