title: How to create "trigger" in MongoDB
body: <p>I would like of create a trigger where, to each subdocument inserted would increment in other collection a field, for generate a count of subdocuments that collection.</p>
  
  <p>I tried create a search using MapReduce, but for Milions of the Registries is very  slow.</p>
  
  <p><em>Note: I use C#, but if you like show how to do in Bson, no problem.</em></p>
  
  <h2>Extructure my collection</h2>
  
  <pre><code>public class Header
  {
      public Header()
      {
          Operation= new List&lt;Operation&gt;();
      }
  
      public ObjectId Id { get; set; }
      public Int64 Code1 {get; set;}
      public Int64 Code2 {get; set;}
      public string Name { get; set; }
      public List&lt;Operation&gt; Operations { get; set; }
  }
  
  public class Operation
  {
      public Operation()
      {
          Itens = new List&lt;Item&gt;();
      }
  
      public string Value { get; set; }
      public List&lt;Item&gt; Item { get; set; }
  }
  
  public class Item
  {
      public string Value { get; set; }
  }
  </code></pre>