Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!