I am trying to to build a mongoose query to find records that match one date, i think its working but it doesn't show anything because the date i have in my array of objects is string and i am using date to compare them.
const startDate = new Date(new Date(req.query.date).setHours(0, 0, 0));
const endDate = new Date(new Date(req.query.date).setHours(23, 59, 59));
const transactions = await Transaction.paginate({ 'payments.date': { $gte: startDate, $lte: endDate } }, { allowDiskUse: true, page: req.query.page });
Here's the schema for payments object
payments: [
{
payment_system: {
type: String,
},
amount: {
type: Number,
},
date: {
index: true,
type: String,
},
},
],
As you can see the date is string, and its indexed. The reason i put it as a string because it would keep the server time instead of the timezone i desired. But that's not the problem the problem is to filter these results by date which is string. Can anyone help me?
Thank you
startDate = moment().startOf('day').toDate()andendDate = moment().endOf('day').toDate()An object representing an expression must have exactly one field: