elixir-mongo / mongodb_ecto

MongoDB adapter for Ecto
Apache License 2.0
368 stars 126 forks source link

How search value in array? #148

Closed renatocassino closed 6 years ago

renatocassino commented 6 years ago

Hello guys.

I'm trying to make a query to search an ID in a list. I have a field called member_ids whith multiple ids.

I'm trying to make this: query = from m in MyModel, where: m.member_ids: [{"$exists": "588e25416e8dee2725c54446"}], select: m

In MyModel I setted the field in this way field :members_ids, {:array, :string}

How can I do this to work? Thanks for this.

ankhers commented 6 years ago

You should be able to do

from m in MyModel, where: ^"588e25416e8dee2725c54446" in m.member_ids
ankhers commented 6 years ago

Closing due to inactivity.