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

125
Visualizações
How to query for an object within an array in mongoose

I'm new to mongoose and I'm having trouble querying for specific objects within an array.

My data model looks like this:

{
  "users": [
    {
      "_id": "61b0d6637e169ddebf72c18a",
      "name": "Brian Test",
      "email": "briantest@gmail.com",
      "password": "xxx",
      "accountType": "type1",
      "__v": 0,
      "title": "title1",
      "about": "about1",
      "education": [
        {
          "recordId": 1,
          "institution": "institution1",
          "title": "title1"
        },
        {
          "recordId": 2,
          "institution": "institution2",
          "title": "title2"
        },
        {
          "recordId": 3,
          "institution": "institution3",
          "title": "title3"
        }
      ]
    }
  ]
}

The query I need is to perform a crud on education records. For it I'll have the user ID and the education record ID.

I'm not sure how to nest the education record query within the user query. I've tried something like this but It's not working.

let user = await User.findOne({_id: req.user.user.id})
let recordToUpdate = await user.education.findOne({recordId: req.body.recordId})
console.log(recordToUpdate)

I'll appreciate if you could give examples for reading, updating and deleting records aswell. Thanks!

about 4 years ago · Juan Pablo Isaza
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