$in with regex

This query is an example from mongodb's documentation. Does apperyio support this or something similar?

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

specifically:

The $in operator can specify matching values using regular expressions of the form /pattern/. You cannot use $regex operator expressions inside an $in.

Consider the following example:

db.inventory.find( { tags: { $in: [ /^be/, /^st/ ] } } )
1 person has
this question
+1
This topic is no longer open for comments or replies.
  • Hi Jerry,

    Here is how to use regex in "$in" clause:



    {
    name: {
    $in: [{
    "$regex": "regexValue1...",
    "$options": "im"
    }, {
    "$regex": "regexValue2...",
    "$options": "im"
    }]
    }
    }


    Regards.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Awesome! Thank you so much for the help. I had read somewhere that $regex couldn't be used with $in - but I'm glad it can, that is so much easier. I tried it and it worked perfectly.

    If you don't mind, I'd like to take this a little deeper. I would like to do a $regex search against regex values in another collection. With SQL I would use a subquery - but I'm unsure if there is an equivalent structure/query to do something like this. I'm picturing something like this:

    {
    company: {
    $in: [{
    "$regex": {"collName":"SavedSearches",
    "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 the previous $regex/$in example. 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,
    Jerry
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • I will start a new post with the secondary topic.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated