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

255
Views
MongoDB $elemMatch on array

I have a document like this :

{
  "values": 
    [
      ["a","231"],
      ["b","232"],
      ["c","233"],
      ["a","235"]  
    ]
}

How to use $elemMatch on value property. want to project elements in values that first element of them are "a".

something like this:

db.test.find({"values" : {$elemMatch: { "matchedElemet"[0]: "a"}}},{"values.$":1})
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use something like this:

db.test.find(
    {
        'values': {
            $elemMatch: {
                $elemMatch: {
                    $in: ['a']
                }
            }
        }
    },
    {
        "values.$": 1
    }
)

or

db.test.find(
    {},
    {
        'values': {
            $elemMatch: {
                $elemMatch: {
                    $in: ['a']
                }
            }
        }
    }
)

I hope I got your requirement correctly and this helps.

over 4 years ago · Santiago Trujillo Report
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!