Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query distinct values of a field #150

Open
tmattio opened this issue Feb 2, 2018 · 4 comments
Open

Query distinct values of a field #150

tmattio opened this issue Feb 2, 2018 · 4 comments

Comments

@tmattio
Copy link

tmattio commented Feb 2, 2018

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!

@ankhers
Copy link
Collaborator

ankhers commented Feb 2, 2018

Can you please tell me what version of this adapter you are currently using?

@tmattio
Copy link
Author

tmattio commented Feb 2, 2018

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.

@ankhers
Copy link
Collaborator

ankhers commented Feb 2, 2018

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.

@tmattio
Copy link
Author

tmattio commented Feb 2, 2018

Thanks you!

I am new to Elixir, but I'll try to look into this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants