Help with Meteor .find on Date Objects.. This one may challenge you

Hi All,

I’ve been struggling with this for a few days now.

I have a database on MongoDB Atlas.

I have a collection with a date object called startDate
When I use Mongo Compass with this prompt it returns the data I need.

{'facebookPageID': '111111111111111', 'startDate.date': {'$gte': new Date('2023-01-01'), '$lte': new Date('2023-12-31')}}

I’m creating a subscription that I pass the facebookPageID and startDate and endDate to.
This is my subscription:

Meteor.publish("dealerApptList", function (facebookPageID, startDate, endDate) {
          if(facebookPageID && startDate && endDate) {
               return Calendar.find({
                    'facebookPageID': facebookPageID,
                    'startDate.date': {'$gte': new Date('2023-01-01T00:00:00.000Z'), '$lte': new Date('2023-12-31T00:00:00.000Z')}
               });
          }else{
               return this.ready();
          }
     });

When I console log the return it’s an empty arr .
If I remove the date part. of the find it returns all records for the facebookPageID supplied as expected.

This is a record as it is returned in mongo Compass:

senderID: "5968391423198799"
XMLSent: false
agent: "Agent Name"
bookingType: "regular"
comments: "Comments Here"
dateAdded: "2023-02-13T01:31:12+00:00"
email: "Miguela.solano2020@icloud.com"
endDate: Object
event_name: "EventName"
facebookPageID: "111111111111111"
first_name: "First Name"
last_name: "Last Name"
phone: "(000)000-0000"
startDate: Object
status: "1"

The startDate Object looks like this:

startDate:
Object
    date: 2023-02-13T22:30:00.000+00:00
    timezone: "America/Chicago"

I’ve tried many variations of the date including using moment(startDate).toISOString().

Everything I have tried returns either an empty array or all the records.

Anytime I mention empty array I am using fetcht() on the returned object.

Example:
const cal = Calendar.find().fetch();

I’ve looked through a doesn’t or more other similar posts without finding a solution.

Specs: Meteor 2.10.0 Latest version of MongoDB Atlas.

My preference would be a moment example as I heavily use moment in this application.

@ [robfallows] I’ve read many of your previous answers on other items like this. I know it’s just me not understanding how to get my find to send the right date format. You’ll probably look at this and say "That bonehead didn’t do this. lol

Not really an answer but I tested your data types and syntax and got results

Thanks much, wish I could say the same.

In Mongodb Compass, if you copy the document, it will copy the JSON, what does your date look like?
Mine looks like this:

"when":{"$date":"2023-12-20T17:46:49.435Z"}

Mine looks like this:

“startDate”: {
“date”: {
“$date”: “2020-01-02T14:00:00.000Z”
},
“timezone”: “America/New_York”
}

does your query works on server? Sometime a query works on server but not in the browser (minimongo)

No all the code I provided is publishing a query on the server side.

Thanks,
Glen

Are you sure you have existing values for the subscription parameters to pass the condition?

Untested, but my gut tells me this should work:

return Calendar.find({
  'facebookPageID': facebookPageID,
  'startDate': {'$gte': new Date('2023-01-01T00:00:00.000Z'), '$lte': new Date('2023-12-31T00:00:00.000Z')}
});