https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
w

wide-stone-93283

10/11/2022, 8:56 PM
Hi there! Do you guys know if there’s a way to evaluate if a list in the attributes contains two values? I tried to create a forced rule that:
Copy code
IF list includes val1 AND list includes val2
but when saving it, it only saves the first condition.
f

fresh-football-47124

10/11/2022, 9:04 PM
Hi Alberto, there are two ways to do this
by adding a second targeting condition, which will be AND’ed
or using regex
I’d be happy to help you figure this out if you like
w

wide-stone-93283

10/11/2022, 9:12 PM
sounds good, thanks Graham. I tried the first approach
but after saving the rule, it only has one condition
f

fresh-football-47124

10/11/2022, 9:12 PM
oh, interesting
if you click on advanced mode
I can help you with that query
w

wide-stone-93283

10/11/2022, 9:13 PM
That’d be awesome, I’m now in the advanced mode
f

fresh-football-47124

10/11/2022, 9:13 PM
we use the mongo syntax there, can you show what you have currently?
w

wide-stone-93283

10/11/2022, 9:14 PM
sure, I see this
I guess we must use something like this?
Copy code
$and: [
      { x: { $ne: 0 } },
      { $expr: { $eq: [ { $divide: [ 1, "$x" ] }, 3 ] } }
   ]
I ended up with this:
Copy code
$and: [
    {"user_tags": {"$elemMatch": {"$eq": "tag1"}}},
    {"user_tags": {"$elemMatch": {"$eq": "tag2"}}}
 ]
f

fresh-football-47124

10/11/2022, 9:23 PM
did you mean $and or $or?
w

wide-stone-93283

10/11/2022, 9:23 PM
yes, I meant $and
Copy code
{
  "$and": [
    {
      "user_tags": {
        "$elemMatch": {
          "$eq": "tag1"
        }
      }
    },
    {
      "user_tags": {
        "$elemMatch": {
          "$eq": "tag2"
        }
      }
    }
  ]
}
f

fresh-football-47124

10/11/2022, 9:24 PM
should work
w

wide-stone-93283

10/11/2022, 9:26 PM
I’ll test real quick, thank you for the help 🙌
it worked, thank you!
f

fresh-football-47124

10/11/2022, 11:39 PM
👍
17 Views