123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Criteria::Queryable

Relationships & Source Files
Namespace Children
Modules:
Classes:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: lib/mongoid/criteria/queryable.rb,
lib/mongoid/criteria/queryable/aggregable.rb,
lib/mongoid/criteria/queryable/expandable.rb,
lib/mongoid/criteria/queryable/key.rb,
lib/mongoid/criteria/queryable/macroable.rb,
lib/mongoid/criteria/queryable/mergeable.rb,
lib/mongoid/criteria/queryable/optional.rb,
lib/mongoid/criteria/queryable/options.rb,
lib/mongoid/criteria/queryable/pipeline.rb,
lib/mongoid/criteria/queryable/selectable.rb,
lib/mongoid/criteria/queryable/selector.rb,
lib/mongoid/criteria/queryable/smash.rb,
lib/mongoid/criteria/queryable/storable.rb,
lib/mongoid/criteria/queryable/extensions/array.rb,
lib/mongoid/criteria/queryable/extensions/big_decimal.rb,
lib/mongoid/criteria/queryable/extensions/boolean.rb,
lib/mongoid/criteria/queryable/extensions/date.rb,
lib/mongoid/criteria/queryable/extensions/date_time.rb,
lib/mongoid/criteria/queryable/extensions/hash.rb,
lib/mongoid/criteria/queryable/extensions/nil_class.rb,
lib/mongoid/criteria/queryable/extensions/numeric.rb,
lib/mongoid/criteria/queryable/extensions/object.rb,
lib/mongoid/criteria/queryable/extensions/range.rb,
lib/mongoid/criteria/queryable/extensions/regexp.rb,
lib/mongoid/criteria/queryable/extensions/set.rb,
lib/mongoid/criteria/queryable/extensions/string.rb,
lib/mongoid/criteria/queryable/extensions/symbol.rb,
lib/mongoid/criteria/queryable/extensions/time.rb,
lib/mongoid/criteria/queryable/extensions/time_with_zone.rb

Overview

A queryable is any object that needs queryable’s dsl injected into it to build MongoDB queries. For example, a ::Mongoid::Criteria is an Queryable.

Examples:

Include queryable functionality.

class Criteria
  include Queryable
end

Instance Attribute Summary

Instance Method Summary

Optional - Included

#asc
#ascending

Add ascending sorting options for all the provided fields.

#batch_size

Adds the option for telling MongoDB how many documents to retrieve in it’s batching.

#collation

::Set the collation.

#comment

Associate a comment with the query.

#cursor_type

::Set the cursor type.

#desc
#descending

Add descending sorting options for all the provided fields.

#hint

Add an index hint to the query options.

#limit

Add the number of documents to limit in the returned results.

#max_scan

Adds the option to limit the number of documents scanned in the collection.

#max_time_ms

Adds a cumulative time limit in milliseconds for processing operations on a cursor.

#no_timeout

Tell the query not to timeout.

#offset

Alias for Optional#skip.

#only

Limits the results to only contain the fields provided.

#order
#order_by

Adds sorting criterion to the options.

#reorder

Instead of merging the order criteria, use this method to completely replace the existing ordering with the provided.

#skip

Add the number of documents to skip.

#slice

Limit the returned results via slicing embedded arrays.

#snapshot

Tell the query to operate in snapshot mode.

#without

Limits the results to only contain the fields not provided.

#add_sort_option

Add a single sort option.

#option

Take the provided criterion and store it as an option in the query options.

#sort_with_list

Add multiple sort options at once.

::Mongoid::Selectable - Included

#atomic_selector

Get the atomic selector for the document.

#embedded_atomic_selector

Get the atomic selector for an embedded document.

#root_atomic_selector_in_db

Get the atomic selector that would match the existing version of the root document.

Aggregable - Included

#group

Add a group ($group) operation to the aggregation pipeline.

#project

Add a projection ($project) to the aggregation pipeline.

#unwind

Add an unwind ($unwind) to the aggregation pipeline.

#aggregation

Add the aggregation operation.

Mergeable - Included

#and_with_operator

Merge criteria with operators using the and operator.

#intersect

Instruct the next mergeable call to use intersection.

#override

Instruct the next mergeable call to use override.

#reset_strategies!

Clear the current strategy and negating flag, used after cloning.

#union

Instruct the next mergeable call to use union.

#__add__

Adds the criterion to the existing selection.

#__expanded__

Adds the criterion to the existing selection.

#__intersect__

Adds the criterion to the existing selection.

#__merge__

Perform a straight merge of the criterion into the selection and let the symbol overrides do all the work.

#__multi__

Adds $and/$or/$nor criteria to a copy of this selection.

#__override__

Adds the criterion to the existing selection.

#__union__

Adds the criterion to the existing selection.

#_mongoid_add_top_level_operation

Combines criteria into a MongoDB selector.

#_mongoid_expand_keys

Takes a criteria hash and expands Key objects into hashes containing MQL corresponding to said key objects.

#_mongoid_flatten_arrays

Calling .flatten on an array which includes a ::Mongoid::Criteria instance evaluates the criteria, which we do not want.

#prepare

Prepare the value for merging.

#use

Use the named strategy for the next operation.

#with_strategy

Add criterion to the selection with the named strategy.

Expandable - Included

#expand_condition_to_array_values

Expand criterion values to arrays, to be used with operators that take an array as argument such as $in.

#expand_one_condition

Expands the specified condition to MongoDB syntax.

Storable - Included

#add_field_expression

Adds a field expression to the query.

#add_logical_operator_expression

Adds a logical operator expression to the selector.

#add_one_expression

Adds an arbitrary expression to the query.

#add_operator_expression

Adds an operator expression to the selector.

Instance Attribute Details

#aliases (readonly)

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable.rb', line 37

attr_reader :aliases

#aliases The aliases.(The aliases.) (readonly)

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable.rb', line 37

attr_reader :aliases

#serializers (readonly)

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable.rb', line 40

attr_reader :serializers

#serializers The serializers.(The serializers.) (readonly)

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable.rb', line 40

attr_reader :serializers

Instance Method Details

#==(other) ⇒ true | false

Is this queryable equal to another object? Is true if the selector and options are equal.

Examples:

Are the objects equal?

queryable == criteria

Parameters:

  • other (Object)

    The object to compare against.

Returns:

  • (true | false)

    If the objects are equal.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable.rb', line 51

def ==(other)
  return false unless other.is_a?(Queryable)
  selector == other.selector && options == other.options
end

#initialize(aliases = {}, serializers = {}, associations = {}, aliased_associations = {}) {|_self| ... }

This method is for internal use only.

Initialize the new queryable. Will yield itself to the block if a block is provided for objects that need additional behavior.

Examples:

Initialize the queryable.

Queryable.new

Parameters:

  • aliases (Hash) (defaults to: {})

    The optional field aliases.

  • serializers (Hash) (defaults to: {})

    The optional field serializers.

  • associations (Hash) (defaults to: {})

    The optional associations.

  • aliased_associations (Hash) (defaults to: {})

    The optional aliased associations.

  • driver (Symbol)

    The driver being used.

Yields:

  • (_self)

Yield Parameters:

  • _self (Queryable)

    the object that the method was called on

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable.rb', line 69

def initialize(aliases = {}, serializers = {}, associations = {}, aliased_associations = {})
  @aliases, @serializers = aliases, serializers
  @options = Options.new(aliases, serializers, associations, aliased_associations)
  @selector = Selector.new(aliases, serializers, associations, aliased_associations)
  @pipeline = Pipeline.new(aliases)
  @aggregating = nil
  yield(self) if block_given?
end

#initialize_copy(other)

Handle the creation of a copy via #clone or #dup.

Examples:

Handle copy initialization.

queryable.initialize_copy(criteria)

Parameters:

  • other (Queryable)

    The original copy.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable.rb', line 84

def initialize_copy(other)
  @options = other.options.__deep_copy__
  @selector = other.selector.__deep_copy__
  @pipeline = other.pipeline.__deep_copy__
end