Reputation: 701
I have an array of Strings that I want to use as a parameter for finding documents in my mongodb.
Basically what I want to do is
// Using query builder
Person.
find().
where('name.last').equals('Ghost' || 'ETC' || 'ETC')....
But instead of using a bunch of or statements, I want to just pass my array of Strings.
Is this possible?
Upvotes: 1
Views: 3563
Reputation: 106385
Just use .in
method, taking $in
operator in play:
Person.
find().
where('name.last').in(['Ghost', 'Foo', 'Bar'])
Quoting the MongoDB docs:
The
$in
operator selects the documents where the value of a field equals any value in the specified array.
Upvotes: 2