0

I have a collection of jobs that have certain skills. Please see the pic below.

enter image description here

As you can see each "job" object has a "skills" array. Skills are shared between different jobs, thus I need to write a get request, so that when a user clicks a skill, it shows different jobs that require this skill. Could you please help me with that. I wrote a code but it does not work.

There are 32 documents overall, each document looks something like this. It has a job name and array of skills.

Some jobs share the same skills. For example IT Business Analyst and Business Analyst.

enter image description here enter image description here

While some jobs share only jew ones. For example, Business Analyst and Technical Manager share "Communication" skill.

enter image description here enter image description here

An output is array of documents that share the same skill. For example array of "Business Analyst" and "Teachnical Manager" objects since they share "Communication" skill.

[
  {
    "name": "Business Analyst",
    "category": "Analyze",
    "skills": [
      {
        "name": "Listener",
        "id": "1"
      },
      {
        "name": "Critical Thinking",
        "id": "2"
      },
      {
        "name": "Problem Solving",
        "id": "3"
      },
      {
        "name": "Analytical",
        "id": "4"
      },
      {
        "name": "Communication",
        "id": "5"
      },
      {
        "name": "Documentation",
        "id": "6"
      },
      {
        "name": "Research",
        "id": "7"
      }
    ]
  },
{
    "name": "Technical Manager",
    "category": "Management",
    "skills": [
      {
        "name": "Team Management",
        "id": "8"
      },
      {
        "name": "Mentorship",
        "id": "9"
      },
      {
        "name": "Decision Making",
        "id": "10"
      },
      {
        "name": "Strategic Thinking",
        "id": "11"
      },
      {
        "name": "Negotiating",
        "id": "12"
      },
      {
        "name": "Communication",
        "id": "5"
      },
      {
        "name": "Financials",
        "id": "13"
      }
    ]
  }

]
NZMAI
  • 536
  • 5
  • 27

1 Answers1

0

This is very basic query, i wonder how you didnt get that.

db.getCollection('skills').find({"skills.name":"Communication"})

Or by skill ID if it is unique

db.getCollection('skills').find({"skills.id":"5"})
Lucia
  • 791
  • 1
  • 8
  • 17