Query Documents by $gte Date


#1
Meteor.publish('events', () => {
	var dateSelector = {date: {$gte : new Date().toISOString()}};
	return Events.find(dateSelector);
});

This is returning 0 documents, even though I know that some have dates greater than todays date.

My document’s dates are in this form:

date: "2016-08-18T16:00:00.000Z"

I’ve gotten this to work when my collection dates were done with new Date(), but can’t seem to get this query to work when they’re in iso…


#2
Meteor.publish('events', () => {
	let today = new Date();
	var dateSelector = {date: {$gte : new Date().toISOString()}};
	return Events.find(dateSelector);
});

Use { date : { $gte : today }}


#3

In addition to the above, you seem to be slightly confused as to what dates actually are: Numbers. That’s why you never work with strings when you try to compare dates.


#4

Thanks for the note, i appreciate it.


#5

I could have sworn I tried this and it didn’t work. but alas, it does work. Thanks!