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

223
Views
How to write a mongo jpa query to search by inner document id?

I am new to mongo DB with JPA. I have a document object like below:

{
'_id': ObjectId("A"),
customer:[
    0: {
        id: 21,
        order:
            {
              id:23, 
              orderName:'orderName1'
            }
       
    },
    1: {
        id: 22,
        order:
            {
               id:12,
               orderName:'Electronics'
            }
    },
]
}

Here I want to get all the orders with orderName starting with "Ele"(example). I've tried:

  1. @Query(value="{'order.orderName':{'$regex':'?0','$options':'i'}}")
  2. @Query("{'order':{'orderName':{'$regex':'?0','$options':'i'}}}")

None of these has worked for me.

Please suggest how to do this.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Demo - https://mongoplayground.net/p/k8Au7Bnmkvg

$regex

db.collection.find({
  "customer.order.orderName": {
    "$regex": "Ele.+",
    "$options": "i"
  }
})

you're trying to query order.orderName but as per your schema it's inside the customer object so use customer.order.orderName

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!