title: Performing bulk update operation: incrementing an object property inside of an array based on existence of name within the array
body: <p>I am assembling a tags collection where I need to perform an update operation with upsert enabled. </p>
  
  <p>**Edit The function I call to add to tags to the collection is passed a tags array that contains the tags the user entered, the name of a category where the tag has been used, and the actual title of the entry. </p>
  
  <p>The name of the category is important since I want to be able to record how many submissions from users that use the same tag also use the same category which is why I have an entries variable that should increment whenever I add a tag that already has that specific category. This array is named categories and has objects, every object in this array has a categoryName property and the amount of entries that use the same category for this specific tag. I also have an array of the title of the entries of users, this array contains strings.</p>
  
  <pre><code>function updateTags(tags, name, simpleString)
  {
       var bulk = myModel.collection.initializeUnorderedBulkOp();
  
       for(var t = 0; t &lt; tags.length, t++)
  {
  
  //important bit..
  
    bulk.find({tag : tags[t]}).upsert().update({ //Query to update document views or a new object to the categories array  })
  }
  
  bulk.execute(cb);
  
  }
  </code></pre>
  
  <p>Here is a sort of algorithmic approach that the query should perform.</p>
  
  <p>-check for the existence of a tag</p>
  
  <p>--if a tag exists check if any categoryName properties from the entries within the categories array match the category name passed into the function</p>
  
  <p>---if that specific categoryName already exists within the array, increment its entries by one.</p>
  
  <p>--if the categoryName does not exist add an object with the properties categoryName set to the name passed to the function and set its entries to one.</p>
  
  <p>regardless of the previous existence of categoryName within categories array, add the title (a string) to the array of title entries.</p>
  
  <p>-if the tag does not exist add a document with the tag, a categories array with a single object that has catagoryName set to the category name passed and its entries set to one. Also add the title to the array of title properties.</p>