Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
Storing an Array of String to a Key in MongoDB

I'm building a post request which will contain various info on each role. E.g in this trial, 'Data Analyst'.

In this position I want to have quite a few sources of data, including things like salary, education and skills. However, I'm using recharts to visualise it, which means although I need a key, e.g Masters's degree, I also need a num value associated, such as below:

const educationData = [
  {
    degree: 'Masters',
    A: 120,

  },
  {
    degree: 'Bachelor',
    A: 98,
  },
  {
    degree: 'PhD',
    A: 86,
  },
  {
    degree: 'Industry',
    A: 99,
  },
  {
    degree: 'Associate',
    A: 85,
  }
];

I would like to store this inside my schema created:

const RolesPositionSchema = new mongoose.Schema(
    {
        title:{type:String, required: true, unique: true},
        desc:{type:String, required: true},
        skills:{type:Array, required: true},
        salary:{type:Array}, 
        education: {type: Array},
        popularity: {type: Number},
        reccomendations: {type: Array},
    },
);

Within this I would like to store the 'educationData' into the DB. Happy to input it in manually for now. I just want to know how to structure my schema/data in the postman request.

E.g Input in "education", stored with "Masters:120", "Bachelor:98", "PhD:86" etc -> within the post request:

{
    "title" : "Data Analyst",
    "desc": "Using both internal and external data sources you will develop insights to identify trends and opportunities whilst highlighting areas or improvement to optimise member interaction. This is a proactive role where you will own how we interpret data, allowing you to   provide valuable insight into the development and implementation of product, customer and channel strategies for our sales, retention, and acquisition goals.",
    "skills":["SQL" ,"Excel", "Tableau", "PowerBI", "Python", "Azure", "AWS", "ETL"],
    "education": ["INPUT AN ARRAY OF EDUCATION AND THEIR VALUES HERE!]
}

Thankyou!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could modify first your payload into the format of schema.

Payload

const educationData = [
  {
    degree: 'Masters',
    A: 120,
  },
  {
    degree: 'Bachelor',
    A: 98,
  },
  {
    degree: 'PhD',
    A: 86,
  },
  {
    degree: 'Industry',
    A: 99,
  },
  {
    degree: 'Associate',
    A: 85,
  }
];

Process

const newEducations = educationData.map(education => {
    return `${education.degree}:${education.A}`;
});

const storeRole = new RolesPositionSchema({
    title: 'Data Analyst',
    desc: 'Using both internal and external data sources you will develop insights to identify trends and opportunities whilst highlighting areas or improvement to optimise member interaction. This is a proactive role where you will own how we interpret data, allowing you to   provide valuable insight into the development and implementation of product, customer and channel strategies for our sales, retention, and acquisition goals.',
    skills: [{Skill value}],
    salary: [{Salary value}],
    education: newEducations,
    popularity: 0,
    reccomendations: [{Recommendation value}]
});

After this saved. Does it that you want?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda