mongodb_ecto
mongodb_ecto copied to clipboard
Query distinct values of a field
I am trying to query the distinct values of a field in all the documents as in: https://docs.mongodb.com/manual/reference/method/db.collection.distinct/
I tried to use the distinct function provided by Ecto (https://hexdocs.pm/ecto/Ecto.Query.html#distinct/3), but I have the following error:
** (Ecto.QueryError) MongoDB adapter does not support distinct clause in this query in query
Here is the code I try to run:
def list_tags do
query =
from(
a in Dataset,
distinct: :tags
)
query
|> Repo.all()
end
If the distinct function is not supported by the adapter, is there any other way to get the distinct values of a field?
Thanks!
Can you please tell me what version of this adapter you are currently using?
I am using the branch ecto-2.1 of this repo:
{:mongodb_ecto, github: "michalmuskala/mongodb_ecto", branch: "ecto-2.1"},
And I have configured the adapter to be Mongo.Ecto.
It looks like we are explicitly disallowing distinct here. I would have to see if we could allow for using the mongo distinct function from this.
Thanks you!
I am new to Elixir, but I'll try to look into this as well.