Module: Mongoid::Criteria::Queryable
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.
Instance Attribute Summary
- #aliases readonly
- #aliases The aliases.(The aliases.) readonly
- #serializers readonly
- #serializers The serializers.(The serializers.) readonly
Optional - Included
Aggregable - Included
| #aggregating Flag for whether or not we are aggregating., #aggregating=, | |
| #aggregating? | Has the aggregable enter an aggregation state. |
| #pipeline, #pipeline The aggregation pipeline. | |
Mergeable - Included
Instance Method Summary
-
#==(other) ⇒ true | false
Is this queryable equal to another object? Is true if the selector and options are equal.
-
#initialize(aliases = {}, serializers = {}, associations = {}, aliased_associations = {}) {|_self| ... }
Internal use only
Internal use only
Initialize the new queryable.
-
#initialize_copy(other)
Handle the creation of a copy via #clone or #dup.
-
#to_mql ⇒ Hash
Returns selector and options of the criteria in form of MongoDB command.
Optional - Included
| #asc | Alias for Optional#ascending. |
| #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 |
|
| #comment | Associate a comment with the query. |
| #cursor_type |
|
| #desc | Alias for Optional#descending. |
| #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 | Alias for Optional#order_by. |
| #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 |
| #_mongoid_flatten_arrays | Calling .flatten on an array which includes a |
| #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.
# File 'lib/mongoid/criteria/queryable.rb', line 51
def ==(other) return false unless other.is_a?(Queryable) selector == other.selector && == other. end
#initialize(aliases = {}, serializers = {}, associations = {}, aliased_associations = {}) {|_self| ... }
Initialize the new queryable. Will yield itself to the block if a block is provided for objects that need additional behavior.
# 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.
# File 'lib/mongoid/criteria/queryable.rb', line 84
def initialize_copy(other) @options = other..__deep_copy__ @selector = other.selector.__deep_copy__ @pipeline = other.pipeline.__deep_copy__ end
#to_mql ⇒ Hash
Returns selector and options of the criteria in form of MongoDB command.
# File 'lib/mongoid/criteria/queryable.rb', line 93
def to_mql { :'$db' => database_name, find: collection.name, filter: selector }.merge() end