| Module | Origin::Selectable |
| In: |
lib/origin/selectable.rb
|
| LINE_STRING | = | "LineString" |
Constant for a LineString $geometry.
@since 2.0.0 |
|
| POINT | = | "Point" |
Constant for a Point $geometry.
@since 2.0.0 |
|
| POLYGON | = | "Polygon" |
Constant for a Polygon $geometry.
@since 2.0.0 |
| negating | [RW] | @attribute [rw] negating If the next spression is negated. @attribute [rw] selector The query selector. |
| selector | [RW] | @attribute [rw] negating If the next spression is negated. @attribute [rw] selector The query selector. |
Add the $and criterion.
@example Add the criterion.
selectable.and({ field: value }, { other: value })
@param [ Array<Hash> ] criterion Multiple key/value pair matches that
all must match to return results.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Add the range selection.
@example Match on results within a single range.
selectable.between(field: 1..2)
@example Match on results between multiple ranges.
selectable.between(field: 1..2, other: 5..7)
@param [ Hash ] criterion Multiple key/range pairs.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Select with an $elemMatch.
@example Add criterion for a single match.
selectable.elem_match(field: { name: "value" })
@example Add criterion for multiple matches.
selectable.elem_match(
field: { name: "value" },
other: { name: "value"}
)
@example Execute an $elemMatch in a where query.
selectable.where(:field.elem_match => { name: "value" })
@param [ Hash ] criterion The field/match pairs.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Add the $exists selection.
@example Add a single selection.
selectable.exists(field: true)
@example Add multiple selections.
selectable.exists(field: true, other: false)
@example Execute an $exists in a where query.
selectable.where(:field.exists => true)
@param [ Hash ] criterion The field/boolean existence checks.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Add a $geoIntersects or $geoWithin selection. Symbol operators must be used as shown in the examples to expand the criteria.
@note The only valid geometry shapes for a $geoIntersects are:
:intersects_line, :intersects_point, and :intersects_polygon.
@note The only valid geometry shape for a $geoWithin is :within_polygon
@example Add a geo intersect criterion for a line.
query.geo_spacial(:location.intersects_line => [[ 1, 10 ], [ 2, 10 ]])
@example Add a geo intersect criterion for a point.
query.geo_spacial(:location.intersects_point => [[ 1, 10 ]])
@example Add a geo intersect criterion for a polygon.
query.geo_spacial(:location.intersects_polygon => [[ 1, 10 ], [ 2, 10 ], [ 1, 10 ]])
@example Add a geo within criterion for a polygon.
query.geo_spacial(:location.within_polygon => [[ 1, 10 ], [ 2, 10 ], [ 1, 10 ]])
@param [ Hash ] criterion The criterion.
@return [ Selectable ] The cloned selectable.
@since 2.0.0
Adds the $in selection to the selectable.
@example Add $in selection on an array.
selectable.in(age: [ 1, 2, 3 ])
@example Add $in selection on a range.
selectable.in(age: 18..24)
@example Execute an $in in a where query.
selectable.where(:field.in => [ 1, 2, 3 ])
@param [ Hash ] criterion The field/value criterion pairs.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Add a $maxDistance selection to the selectable.
@example Add the $maxDistance selection.
selectable.max_distance(location: 10)
@param [ Hash ] criterion The field/distance pairs.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Adds $mod selection to the selectable.
@example Add the $mod selection.
selectable.mod(field: [ 10, 1 ])
@example Execute an $mod in a where query.
selectable.where(:field.mod => [ 10, 1 ])
@param [ Hash ] criterion The field/mod selections.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Adds a $near criterion to a geo selection.
@example Add the $near selection.
selectable.near(location: [ 23.1, 12.1 ])
@example Execute an $near in a where query.
selectable.where(:field.near => [ 23.2, 12.1 ])
@param [ Hash ] criterion The field/location pair.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Adds a $nearSphere criterion to a geo selection.
@example Add the $nearSphere selection.
selectable.near_sphere(location: [ 23.1, 12.1 ])
@example Execute an $nearSphere in a where query.
selectable.where(:field.near_sphere => [ 10.11, 3.22 ])
@param [ Hash ] criterion The field/location pair.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Is the current selectable negating the next selection?
@example Is the selectable negating?
selectable.negating?
@return [ true, false ] If the selectable is negating.
@since 1.0.0
Adds the $nin selection to the selectable.
@example Add $nin selection on an array.
selectable.nin(age: [ 1, 2, 3 ])
@example Add $nin selection on a range.
selectable.nin(age: 18..24)
@example Execute an $nin in a where query.
selectable.where(:field.nin => [ 1, 2, 3 ])
@param [ Hash ] criterion The field/value criterion pairs.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Adds $nor selection to the selectable.
@example Add the $nor selection.
selectable.nor(field: 1, field: 2)
@param [ Array ] criterion An array of hash criterion.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Negate the next selection.
@example Negate the selection.
selectable.not.in(field: [ 1, 2 ])
@example Add the $not criterion.
selectable.not(name: /Bob/)
@example Execute a $not in a where query.
selectable.where(:field.not => /Bob/)
@param [ Hash ] criterion The field/value pairs to negate.
@return [ Selectable ] The negated selectable.
@since 1.0.0
Adds $or selection to the selectable.
@example Add the $or selection.
selectable.or(field: 1, field: 2)
@param [ Array ] criterion An array of hash criterion.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Construct a text search selector.
@example Construct a text search selector.
selectable.text_search("testing")
@example Construct a text search selector with options.
selectable.text_search("testing", :$language => "fr")
@param [ String, Symbol ] terms A string of terms that MongoDB parses
and uses to query the text index.
@param [ Hash ] opts Text search options. See MongoDB documentation
for options.
@return [ Selectable ] The cloned selectable.
@since 2.2.0
This is the general entry point for most MongoDB queries. This either creates a standard field: value selection, and expanded selection with the use of hash methods, or a $where selection if a string is provided.
@example Add a standard selection.
selectable.where(name: "syd")
@example Add a javascript selection.
selectable.where("this.name == 'syd'")
@param [ String, Hash ] criterion The javascript or standard selection.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Add a $size selection for array fields.
@example Add the $size selection.
selectable.with_size(field: 5)
@note This method is named with_size not to conflict with any existing
#size method on enumerables or symbols.
@example Execute an $size in a where query.
selectable.where(:field.with_size => 10)
@param [ Hash ] criterion The field/size pairs criterion.
@return [ Selectable ] The cloned selectable.
@since 1.0.0
Adds a $type selection to the selectable.
@example Add the $type selection.
selectable.with_type(field: 15)
@example Execute an $type in a where query.
selectable.where(:field.with_type => 15)
@note vurl.me/PGOU contains a list of all types.
@param [ Hash ] criterion The field/type pairs.
@return [ Selectable ] The cloned selectable.
@since 1.0.0