I have a string field in a collection which stores date in this format 3 Mar 2022
.
Is there anyway to apply $gt
and $lt
operators on this in the query? Or is there any other way to query this field?
I am using nodejs/mongoose for querying.
Schema sample
export const SampleSchema = new EntitySchema(
{
startValidity: { type: String },
endValidity: { type: String },
},
{ collection: 'Sample'},
)
Please help.
if your date field is of type date, then you can query like
{ $and: [{ myDateField: { $gte: myDateQuery1} }, { myDateField: { $lte: myDateQuery1} }] }