Method: Mongoid::Contextual::Mongo#distinct

Defined in:
lib/mongoid/contextual/mongo.rb

#distinct(field) ⇒ Array<Object>

Get the distinct values in the db for the provided field.

Examples:

Get the distinct values.

context.distinct(:name)

Parameters:

  • field (String, Symbol)

    The name of the field.

Returns:

  • (Array<Object>)

    The distinct values for the field.

Since:

  • 3.0.0



104
105
106
# File 'lib/mongoid/contextual/mongo.rb', line 104

def distinct(field)
  view.distinct(klass.database_field_name(field))
end