я решаю этот вопрос
db.collections.aggregate([
{
"$project": {
"doctor":1,
"dates":{ $dateToString: { format: "%Y-%m-%d", date: "$schedule_date" } },
"from":{
"$dateFromString": {
"timezone": "+05:30",
"dateString": {"$concat": [{ $dateToString: { format: "%Y-%m-%d", date: "$schedule_date" } },
{ "$concat": ["$schedule_time.from", ":00"] } ] },
}
},
"to":{
"$dateFromString": {
"timezone": "+05:30",
"dateString": {"$concat": [{ $dateToString: { format: "%Y-%m-%d", date: "$schedule_date" } },
{ "$concat": ["$schedule_time.to", ":00"] } ] },
}
}
},
},{
$match:{
$and: [{
"doctor": ObjectId(obj.doctor)
},
{
$or: [
{
$and: [
{
from: {
$gte: new Date(from)
}
},
{
to: {
$lte: new Date(to)
}
}
]
},
{
$and: [
{
from: {
$gte: new Date(from)
}
},
{
from: {
$lte: new Date(from)
}
}
]
}, {
$and:[
{
to: {
$gte: new Date(to)
}
},
{
to: {
$lte: new Date(to)
}
}
]
}
]
}]
}
}
])