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