title: Possible bug when observing a cursor, when deleting from collection
body: <p>I've run into an interesting possible bug, but in this case it may be caused by the lack of a function for me to use to delete a document when observing a collection. Or I am misusing <code>observe</code>... which could very well be the case!</p>
  
  <p>Here is sample code that will reproduce the issue I'm having.</p>
  
  <p><strong>I'm using the devel branch as of this writing, so I'm not sure if this works in 0.3.5</strong></p>
  
  <h2>observebug.html</h2>
  
  <pre><code>&lt;head&gt;
      &lt;title&gt;observebug&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      {{&gt; main}}
  &lt;/body&gt;
  
  &lt;template name="main"&gt;
      &lt;h1&gt;Example showing possible bug in Meteor wrt observe&lt;/h1&gt;
      &lt;div&gt;
          &lt;p&gt;Try to delete a note. You will notice that it doesn't appear to get deleted. However, on the server, the delete did occur. Refresh the page to see that the delete did in fact occur.&lt;/p&gt;
          &lt;h2&gt;Notes:&lt;/h2&gt;
          &lt;ul&gt;
              {{#each notes}}
                  {{&gt; note_row}}
              {{/each}}
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;template name="note_row"&gt;
      &lt;li&gt;{{title}} &lt;button name="delete"&gt;delete&lt;/button&gt;&lt;/li&gt;
  &lt;/template&gt;
  </code></pre>
  
  <h2>observebug.js</h2>
  
  <pre><code>// CLIENT
  
  if (Meteor.is_client) {
      Notes = new Meteor.Collection("notes_collection");
  
      Meteor.autosubscribe(function () {
          Meteor.subscribe("notes_subscription");
      });
  
      Template.main.notes = function () {
          return Notes.find();
      };
  
      Template.note_row.events = {
          "click button[name='delete']": function (evt) {
              Meteor.call("deleteNote", this._id, function (error, result) {
                  if (!error) {
                      console.log("Note deletion successful.");
                  } else {
                      console.log("Error when deleting note.");
                  }
              });
          }
      };
  }
  
  // SERVER
  
  if (Meteor.is_server) {
      Notes = new Meteor.Collection("notes_collection");
  
      Meteor.methods({
          "deleteNote": function (note_id) {
              try {
                  Notes.remove(note_id);
                  return true;
              } catch (e) {
                  return false;
              }
          }
      });
  
      Meteor.publish("notes_subscription", function () {
          var notes = Notes.find({}, {sort: {title: 1}});
          var self = this;
  
          // What we're doing here is basically making an exact duplicate
          // of the notes collection. A possible use-case for this would be
          // to actually make changes to the copied collection on the fly,
          // such as adding new fields without affecting the original
          // collection.
          var upsertHandler = function (note, idx) {
              note.some_new_field = 100;
              self.set("notes_collection", note._id, note);
              self.flush();
          };
  
          var handle = notes.observe({
              added: upsertHandler,
              changed: upsertHandler,
              removed: function (note, idx) {
                  // As far as I can tell, unset won't remove the document,
                  // only attributes of the document. I don't think there's
                  // a method to handle actually removing a whole document?
                  self.unset("notes_collection", note._id);
                  self.flush();
              }
          });
  
          self.onStop(function () {
              handle.stop();
              self.flush();
          });
      });
  
      // Add example notes
      Meteor.startup(function () {
          if (Notes.find().count() === 0) {
              Notes.insert({title: "Note #1"});
              Notes.insert({title: "Note #2"});
              Notes.insert({title: "Note #3"});
              Notes.insert({title: "Note #4"});
              Notes.insert({title: "Note #5"});
              Notes.insert({title: "Note #6"});
          }
      });
  }
  </code></pre>
  
  <h2>What you'll be seeing</h2>
  
  <p>When you start this application up, you'll see 6 example "notes", each with a delete button. I suggest having your console open so you can see the <code>console.log</code>s. Click the delete button on any note. The note does get deleted, however this doesn't get reflected back up to the client.</p>
  
  <p>I suspect the issue lies in how I'm leveraging <code>observe</code> to create a copy of the collection (which I can then manipulate without affecting the original collection). I feel like I need a function that deletes a whole document, not just some attributes (<code>unset</code>).</p>
  
  <p><strong>EDIT: See the example in action over at <a href="http://observebug.meteor.com/" rel="nofollow">http://observebug.meteor.com/</a></strong></p>