3

  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.

Pallab
  • 145
  • 1
  • 9
  • It's still unclear. What field decides absents – Gibbs May 17 '22 at 03:05
  • I have added required JSON. Please have a look. @Gibbs – Pallab May 17 '22 at 03:26
  • This is still unclear. What is "May or may not"? Why do you want on 2 of 3 shifts in the results? – nimrod serok May 17 '22 at 16:04
  • Actually, this _id belongs to the attendance collection _id. In the attendance collection, may not have Week off, absent, holiday and leave relation. So I mention this. @nimrodserok – Pallab May 18 '22 at 11:10
  • We need your expected result from the data that is in the playground. It is not clear since you publish expected results from other data – nimrod serok May 18 '22 at 20:43

0 Answers0