Method: Mongoid::Criterion::Exclusion#only

Defined in:
lib/mongoid/criterion/exclusion.rb

#only(*args) ⇒ Object

Adds a criterion to the Criteria that specifies the fields that will get returned from the Document. Used mainly for list views that do not require all fields to be present. This is similar to SQL “SELECT” values.

Options:

args: A list of field names to retrict the returned fields to.

Example:

criteria.only(:field1, :field2, :field3)

Returns: self



60
61
62
# File 'lib/mongoid/criterion/exclusion.rb', line 60

def only(*args)
  @options[:fields] = args.flatten if args.any?; self
end