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:
@Query(value="{'order.orderName':{'$regex':'?0','$options':'i'}}")
@Query("{'order':{'orderName':{'$regex':'?0','$options':'i'}}}")
None of these has worked for me.
Please suggest how to do this.
Demo - https://mongoplayground.net/p/k8Au7Bnmkvg
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.