title: Meteor: How to add and query Dates in Mongodb with Momentjs
body: <p>I want to show all objects which are due today. Everything works properly with my fixture data. But newly added objects won't show up.</p>
  
  <p><strong>Fixture</strong></p>
  
  <pre><code>...
  var today = moment().toDate();
  
      Cards.insert({
          deckName: javascriptId,
          due: today,
          front: 'blaablaa',
          back: 'blaablaablaa'
      });
  ...
  </code></pre>
  
  <p><strong>Show objects</strong></p>
  
  <pre><code>Template.showCards.helpers({
      cards: function () {
          var end = moment().toDate();
  
          return Cards.findOne({
              deckName: this._id,
              due: {"$lte": end}
          });
      }
  </code></pre>
  
  <p><strong>Add new due date to hide an object</strong></p>
  
  <pre><code>    Template.showCards.events({
      ...
          'click #difficulty button': function(event) {
          var incBy = parseInt(event.target.value);
          console.log(incBy);
          console.log(typeof incBy);
          var today = moment();
          var newDue = moment(today).add(incBy,'days').toDate();
          Cards.update(
              this._id, {
                  $set: {due: newDue}
                  }
              );
      }
  });
  </code></pre>
  
  <p><strong>Add new objects</strong></p>
  
  <pre><code>Template.addCards.events({
      'submit form': function (event, template) {
          event.preventDefault();
          var deckNameVar = event.target.deckName.value;
          var frontVar = event.target.front.value;
          var backVar = event.target.back.value;
          var today = moment().toDate();
          Cards.insert({
              deckName: deckNameVar,
              due: today,
              front: frontVar,
              back: backVar
          });
      }
  });
  </code></pre>
  
  <p>New objects will be properly added to the database but for some reason they don't show up.</p>