I made some complex data with mongoose schema.
And I want to find it by some specific condition.
Here is my data that is sent by post.
{
"clientID": "1234",
"clientOrder": [{
"cartNumber":0,
"departure": {
"pickUpTimeFrom": "2019-02-03T13:00",
"pickUpTimeto": "2019-02-03T15:00"
},
"destination": {
"pickUpTimeFrom": "2019-02-04T13:00",
"pickUpTimeto": "2019-02-04T15:00"
}
},
"clientID": "1234",
"clientOrder": [{
"cartNumber":1,
"departure": {
"pickUpTimeFrom": "2019-02-03T13:00",
"pickUpTimeto": "2019-02-03T15:00"
},
"destination": {
"pickUpTimeFrom": "2019-02-04T13:00",
"pickUpTimeto": "2019-02-04T15:00"
}
}]
}
And I want to find a specific array by the condition of date at "cartNumber: 0".
So, I made this find "cartNumber:0".
But, it doesn't send any date.
And , I couldn't make date condition like "2019-02-03" of "departure" even.
Could you help me to make the correct code?
const allInform = await Order.find({
clientOrder: {
$elemMatch: {
cartNumber: 0,
},
},
});