Count how many times an element in an array matches in other similar arrays

Hello everyone, I’m new to MongoDB so I’m asking for your advice.

I backend on .net 6+EF and database with documents of the following structure:

Document structure
{
   "_id":{
      "$oid":"632ca3a350094540af4af9bc"
   },
   "DocumentNumber":"254334",
   "CreateDate":{
      "$date":{
         "$numberLong":"1662401057259"
      }
   },
   "Firm":{
      "_id":48,
      "Name":"Jhon D.",
      "Contract":"189744",
      "ContractPerson":"Jhon D",
      "Phones":"123456778"
   },
   "DocumentData":[
      {
         "Type":1,
         "Rows":[
            {
               "Department":"Sector 1",
               "Settlement":"NY",
               "WorkType":"3",
               "SubstationName": "Sub1",
               "Objects":[
                  {
                     "Name":"Object 322",
                     "Elements":[
                        "212",
                        "211",
                        "210",
                        "209",
                        "208",
                        "207"
                     ]
                  }
               ]
            },
            {
               "Department":"Sector 2",
               "Settlement":"SF",
               "WorkType":"2",
               "SubstationName": "Sub2",
               "Objects":[
                  {
                     "Name":"Object 21",
                     "Elements":[
                        "183",
                        "184",
                        "185",
                        "186",
                        "187",
                        "188",
                        "189"
                     ]
                  }
               ]
            },
            ...
         ]
      }
      {
         "Type":3,
         "Rows":[
            {
               "Department":"Sector 1",
               "Settlement":"NY",
               "WorkType":"1",
               "SubstationName": null,
               "Objects":[
                  {
                     "Name":"Object 1",
                     "Elements":[
                        "3",
                        "32",
                        "56",
                        "12/23",
                        "78"
                     ]
                  }
               ]
            },
            {
               "Department":"Sector 2",
               "Settlement":"SF",
               "WorkType":"1",
               "SubstationName": null,
               "Objects":[
                  {
                     "Name":"Object 2",
                     "Elements":[
                        "3",
                        "56",
                        "78",
                        "88",
                        "99"
                     ]
                  }
               ]
            },
            ...
         ]}]}

I need to take one of these documents and count how many times each element of the DocumentData.Rows.Objects.SubNames array occurs in other documents in similar objects. That is, the coincidence must correspond to something like the following condition:

Filter
Where(x => x.DocumentData.Type == takenDocument.DocumentData.Type && x.DocumentData.Type.Rows.Department == takenDocument.DocumentData.Type.Rows.Department && x.DocumentData.Type.Rows.Settlement == takenDocument.DocumentData.Type.Rows.Settlement &&
x.DocumentData.Type.Rows.WorkType == takenDocument.DocumentData.Type.Rows.WorkType &&
x.DocumentData.Type.Rows.SubstationName == takenDocument.DocumentData.Type.Rows.SubstationName &&
x.DocumentData.Type.Rows.SubstationName.Objects.Name == takenDocument.DocumentData.Type.Rows.SubstationName.Objects.Name)

And at the output, get this document with fields with coincidence counts:

Result
{
   "_id":{
      "$oid":"632ca3a350094540af4af9bc"
   },
   "DocumentNumber":"254334",
   "CreateDate":{
      "$date":{
         "$numberLong":"1662401057259"
      }
   },
   "Firm":{
      "_id":48,
      "Name":"Jhon D.",
      "Contract":"189744",
      "ContractPerson":"Jhon D",
      "Phones":"123456778"
   },
   "DocumentData":[
      {
         "Type":1,
         "Rows":[
            {
               "Department":"Sector 1",
               "Settlement":"NY",
               "WorkType":"3",
               "SubstationName": "Sub1",
               "Objects":[
                  {
                     "Name":"Object 322",
                     "Elements":[
                        { "212", 1 }, <- Count match
                        { "211", 0 }, 
                        { "210", 0 }, 
                        { "209", 0 }, 
                        { "208", 0 }, 
                        { "207", 2 }, 
                        { "313", 2 }, 
                        { "180", 2 },
                        { "181", 0 }, 
                     ]
                  }
               ]
            },
            ...
         ]
      }
      {
         "Type":3,
         "Rows":[
            {
               "Department":"Sector 1",
               "Settlement":"NY",
               "WorkType":"1",
               "SubstationName": null,
               "Objects":[
                  {
                     "Name":"Object 1",
                     "Elements":[
                        { "3",        0 }, <- Count match
                        { "32",      1 }, 
                        { "56",      2 }, 
                        { "12/23", 2 }, 
                        { "78".      0 }  
                     ]
                  }
               ]
            },
            {
               "Department":"Sector 2",
               "Settlement":"SF",
               "WorkType":"1",
               "SubstationName": null,
               "Objects":[
                  {
                     "Name":"Object 2",
                     "Elements":[
                        { "3",    0 }, <- Count match
                        { "56",  0 },
                        { "78",  4 },
                        { "88",  0 },
                        { "99",  1 }
                     ]
                  }
               ]
            },
            ...
         ]}]}

I will be grateful for any help.