Reputation: 57
{
"category" : {
"100" : {
"location" : "class.xyz.20"
}
}
}
How can I direct Apply regex on location key field in MongoDB Like
{"location" : {'$regex' : "class."}}
how can I Do That
Upvotes: 1
Views: 78
Reputation: 198
I have used regex in aggregate pipelines, You can try it out on find too (not sure on the syntax for find
you can check the docs for it).
Here is how I used regEx in Aggregate.
db.collection.aggregate([
{ $match: { "field": { $regex: "someText", $options: 'i'} } }
]);
You can read more about options here
Upvotes: 1