Skip to content

Query distinct values of a field #150

@tmattio

Description

@tmattio

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions