Hi there! Do you guys know if there’s a way to eva...
# ask-questions
w
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
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
sounds good, thanks Graham. I tried the first approach
but after saving the rule, it only has one condition
f
oh, interesting
if you click on advanced mode
I can help you with that query
w
That’d be awesome, I’m now in the advanced mode
f
we use the mongo syntax there, can you show what you have currently?
w
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
did you mean $and or $or?
w
yes, I meant $and
Copy code
{
  "$and": [
    {
      "user_tags": {
        "$elemMatch": {
          "$eq": "tag1"
        }
      }
    },
    {
      "user_tags": {
        "$elemMatch": {
          "$eq": "tag2"
        }
      }
    }
  ]
}
f
should work
w
I’ll test real quick, thank you for the help 🙌
it worked, thank you!
f
👍