Query Documents by $gte Date

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…

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

Use { date : { $gte : today }}

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.

1 Like

Thanks for the note, i appreciate it.

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