Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda