title: Passing Variables to a MongoDB View
body: <p>i'm trying to make views in MongoDB to avoid unnecessary returns. In the documentation says that the aggregation functions can take variables with a double dollar sign, taking this in mind i have created a view that in this example should take one variable to filter customerIds and group the results to sum the payments of different documents.</p>
  
  <p>Example:</p>
  
  <pre><code>db.createView(
    "viewName",
    "myCollection",
    [{
      $match: {  "customerId": "$$customerId", }
    },{
      $group: {
        _id: null,
        total: "$amount",
      }
    }]
  )
  </code></pre>
  
  <p>The view is created OK and if i put some valid customerId in the aggregation function that works ok, but i don't have the slightest idea how to execute the view and pass the <code>customerID</code> that i need.</p>
  
  <p>Any ideas? The mongodb documentation does not help me in this situation and i really need to create this as a view, since there are many applications that will connect to this view(s).</p>
  
  <p>I have tried:
      db.viewName.find({customerId: "some valid id"});</p>