meteor - How to compare mongodb string date fields -


in meteor trying return documents mongo purchase_date after today's date. within context of aslagle/reactive-table filter function knows key search on

i using:

            var today = new date();             var dd = today.getdate();              var mm = today.getmonth()+1;              var yyyy = today.getfullyear();              var fulldate = mm + '/' + dd + '/' + yyyy;              ({"$gte": fulldate}) 

today 5/30/15 , format of field same string 0/00/00 format has month greater 5 rather month day , year greater passed in date. seems checking first number (month) returning greater month 5. gets me things 7/20/00 in past , need documents date after today's date in future.

how done inside mongo selector?

i'd recommend migrating string-based dates actual dates. here's example of how create migration (assuming transactions name of collection):

meteor.startup(function() {   var docs = transactions.find({}, {fields: {purchase_date: 1}}).fetch();   _.each(docs, function(doc) {     var pd = new date(doc.purchase_date);     transactions.update(doc._id, {$set: {purchase_date: pd}});   }); }); 

if add code anywhere under server directory, migration should happen server starts (make sure remove code after has run). i'd recommend trying on backup of database first make sure want.

alternatively, there migrations package can use.

after db has been updated, can see this example how query based on date.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -