Below is my aggregation
db.customers.aggregate([{
$match: {
"CDF.UTILITYTYPE.D1.G1" : "12387835"
}
}, {
$project: {
_id:0,
"CDF.UTILITYTYPE.D1.G22.NAME":1,
"CDF.UTILITYTYPE.D1.G1":1,
"CDF.UTILITYTYPE.D5.EVENT": {
$filter: {
input: "$CDF.UTILITYTYPE.D5.EVENT",
as: "item",
cond: { $eq: [ "$$item.TIME", "12-04-2018 15:46:02" ] }
}
}
}
}
]).pretty();
i am comparing TIME field here i actually want to compare "06-2022" as a substring instead of "12-04-2018 15:46:02" this whole date and time format
2
Answers
You never store date/time values as string, it’s a design flaw. Store always proper
Date
objects.Once you corrected the data type, e.g. with
you can filter by using for example
or supposingly