'Mongodb unmatch aggregate lookup
I am very new in Mongodb and nodejs. I am trying to make attendance system and have multiple collection like attendances, shifts, leaves, Holidays. In the shifts collection have Week Off but obviously absents are not in record. I have created a Playground as per my basic reach - Mongo Playground
My attendance collections as follows.
[
{
"_id": ObjectId("6249c77a99e5c26e50736c02"),
"employee": ObjectId("622061b73b2eaac4b15d42e4"),
"date": "2022-04-03T16:12:42.328Z"
},
{
"_id": ObjectId("624a700199e5c26e50736c07"),
"employee": ObjectId("622061b73b2eaac4b15d42e4"),
"date": "2022-04-06T04:11:45.891Z"
}
]
My shift collection as follow
[
{
"_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"
}
]
}
]
Here I need to get Week Off that have marked with employee and date but not related to attendance collections and as well as need employees wise Absents date in this same result which have no record and related to any collection.
I need something like this.
[
{
"_id": ObjectId("6249c77a99e5c26e50736c02"),
"date": "2022-04-03T16:12:42.328Z",
"employee": ObjectId("622061b73b2eaac4b15d42e4"),
"shift": {
"_id": ObjectId("6272e84b6fc62f16bd0f337c"),
"date": "2022-04-03",
"name": "Day"
}
},
{
"_id": ObjectId("622054b73b2eaac4b14442ee"), //Not required
"date": "2022-04-04T00:00:00.000Z",
"employee": ObjectId("622061b73b2eaac4b15d42e4"),
"shift": {
"_id": ObjectId("6272e84c6fc62f16bd0f337e"),
"date": "2022-04-04",
"name": "Week Off"
}
},
{
"_id": ObjectId("622061b73b2eaac4b14442ee"),
"date": "2022-04-05T00:00:00.000Z",
"employee": ObjectId("622061b73b2eaac4b15d42e4"),
"shift": {
"_id": ObjectId("6272e8546fc62f16bd0f337f"),
"date": "2022-04-05",
"name": "Night"
}
},
{
"_id": ObjectId("624a700199e5c26e50736c07"), //Not required
"date": "2022-04-06T00:00:00.000Z",
"employee": ObjectId("622061b73b2eaac4b15d42e4"),
"absent": true
}
]
Please help me.
Solution 1:[1]
Solved, instead of turning a bigint into a string, just store it as an string
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | akkoboi |
