Jerry7185911
Posts: 0
Joined: Thu Oct 23, 2014 9:18 pm

regex/collection equivalent of a like/subquery

I would like to do a $regex search against regex values in another collection. With SQL I would use a subquery and "like" - but I'm unsure if there is an equivalent structure/query to do something like this. I know this is not correct, but I'm picturing something like this - just not sure of the correct syntax - especially to indicate the specific column to do the regex against:

{
company: {
$in: [{
"$regex": {"collName":"SavedSearches", "include":"search",
"owner":"5278ef66e4b01085e4b79482"},
"$options": "im"
}]
}
}

where SavedSearches has 3 columns:
_id
owner (user id - each user may have multiple saved searches)
search (string containing regex expression to search for)

_id owner search
5432e856e4b013192ec44d30 5278ef66e4b01085e4b79482 googl
54401e92e4b05c4ac3b7be7c 5278ef66e4b01085e4b79482 appl

So the query would return rows for companies including "Google" and "Apple" and "Snapple".

Is this possible? If not, I'm thinking I will have to store saved searches in an array and build the query on the fly using "$in array of $regex". But i would prefer to do a "subquery" style approach where I could potentially search for matches across multiple users using a job and pushnotification.

thanks in advance.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

regex/collection equivalent of a like/subquery

Jerry,

Not sure if you've read the mongodb equivalent of like syntax ( which is the db appery is using in the background )

Check this out if not:

http://stackoverflow.com/questions/33...

Let me know if I can help otherwise...

Bruce
HTTPS://www.linkedin/in/Jbrucestuart

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

regex/collection equivalent of a like/subquery

Hello Jerry,

Please look at the Bruce's reply, he gave your sage advice. Bruce, thank you.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

regex/collection equivalent of a like/subquery

Evgene, You bet ..... you and your team help out so much ---- and you've helped me with I'm sure not my only problem.... trying to be a good citizen and keep up the karma lol....

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

regex/collection equivalent of a like/subquery

Bruce,

Thank you for the kind words :)

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

regex/collection equivalent of a like/subquery

Jerry,

Here's a better link (as I'm working with Regex like queries in my app right now):

http://docs.mongodb.org/manual/refere...

(that's the mongodb user manual - and it looks like the only syntax that works with our version is the sytax using a query like this (this is the query I've just put in my app that's working right now)....

{ s_coursename: { $regex: 'Las Colinas.*', $options: 'i' } }

change s_coursename to the field in yourdb (or multiples if you have multiple fields to do regex on) --- and the 'Las Colinas.' - the . gives you anything with Las Colinas in the name and anything in the balance (front or back it seems). and the options 'i' is to ignore case. Works great. As a side note I do have an index on s_coursename - and I did get a mongodb error with the same query - previous to having an index on that field.

Best,

Bruce
https://www.linkedin/in/jbrucestuart

Jerry7185911
Posts: 0
Joined: Thu Oct 23, 2014 9:18 pm

regex/collection equivalent of a like/subquery

Thank you - this is helpful information. not quite what I was wanting, but I think I need to stop thinking in "relational" terms of subqueries. The links above will move me in the right direction. thanks!

Return to “Issues”