Database

db={attendances:[{"_id":ObjectId("6249c77a99e5c26e50736c02"),"employee":ObjectId("622061b73b2eaac4b15d42e4"),"createdAt":"2022-04-03T16:12:42.328Z"},{"_id":ObjectId("624a700199e5c26e50736c07"),"employee":ObjectId("622061b73b2eaac4b15d42e4"),"createdAt":"2022-04-06T04:11:45.891Z"}],shifts:[{"_id":ObjectId("6272e84b6fc62f16bd0f337d"),"month":"2022-04","employee":ObjectId("622061b73b2eaac4b15d42e4"),"shift":[{"_id":ObjectId("6272e84b6fc62f16bd0f337c"),"date":"2022-04-03","name":"Day"},{"_id":ObjectId("6272e84c6fc62f16bd0f337e"),"date":"2022-04-04","name":"Week Off"},{"_id":ObjectId("6272e8546fc62f16bd0f337f"),"date":"2022-04-5","name":"Night"}]}]}

Query

db.attendances.aggregate([{$lookup:{from:"shifts",let:{employee:"$employee",month:{$dateToString:{date:{$toDate:"$createdAt"},format:"%Y-%m"}},},pipeline:[{$match:{$expr:{"$and":[{$eq:["$$employee","$employee"]},{$eq:["$$month","$month"]}]}},},],as:"shifts"}},{$unwind:{"path":"$shifts","preserveNullAndEmptyArrays":true}},{"$project":{_id:1,employee:1,coordinate:1,image:1,createdAt:1,shift:{"$filter":{"input":"$shifts.shift","cond":{$eq:["$$this.date",{$dateToString:{date:{$toDate:"$createdAt"},format:"%Y-%m-%d"}}]}}},}},{$unwind:{"path":"$shift","preserveNullAndEmptyArrays":true}},])

Result