Documentation ¶
Overview ¶
Package query contains helper functions to construct [mongodb query and project operators](https://docs.mongodb.com/manual/reference/operator/)
Index ¶
- type A
- type EachModifier
- type GeometryOperator
- type M
- func AddToSet(spec interface{}) M
- func All(value interface{}) M
- func And(expr ...interface{}) M
- func Bit(spec interface{}) M
- func BitsAllClear(mask interface{}) M
- func BitsAllSet(mask interface{}) M
- func BitsAnyClear(mask interface{}) M
- func BitsAnySet(mask interface{}) M
- func Box(x1, y1, x2, y2 float64) M
- func Center(x, y, radius float64) M
- func CenterSphere(x, y, radius float64) M
- func Comment(comment string) M
- func CurrentDate(spec interface{}) M
- func ElemMatch(query interface{}) M
- func Eq(value interface{}) M
- func Exists(v bool) M
- func Explain() M
- func Expr(expr interface{}) M
- func FirstElemMatch(spec interface{}) M
- func GeoIntersects(geometry interface{}) M
- func GeoWithIn(geometry interface{}) M
- func Gt(value interface{}) M
- func Gte(value interface{}) M
- func Hint(hint interface{}) M
- func In(value interface{}) M
- func Inc(spec interface{}) M
- func JSONSchema(schema interface{}) M
- func Lt(value interface{}) M
- func Lte(value interface{}) M
- func Max(spec interface{}) M
- func MaxIndex(bound interface{}) M
- func MaxTimeMS(ms int64) M
- func MergeOperators(operators ...M) M
- func Meta(metaDataKeyword string) M
- func Min(spec interface{}) M
- func MinIndex(bound interface{}) M
- func Mod(divisor, remainder int64) M
- func Mul(spec interface{}) M
- func Natural(direction int) M
- func Ne(value interface{}) M
- func Nin(value interface{}) M
- func Nor(expr ...interface{}) M
- func Not(expr interface{}) M
- func Or(expr ...interface{}) M
- func OrderBy(sort interface{}) M
- func Polygon(point ...[2]float64) M
- func Pop(spec interface{}) M
- func Pull(spec interface{}) M
- func PullAll(spec interface{}) M
- func Push(spec interface{}) M
- func Query(expr interface{}) M
- func Rand() M
- func Regex(re primitive.Regex) M
- func Rename(spec interface{}) M
- func ReturnKey() M
- func Set(spec interface{}) M
- func SetOnInsert(spec interface{}) M
- func ShowDiskLoc() M
- func Size(n int) M
- func SliceN(num int) M
- func SliceSkip(skip, limit int) M
- func Type(numberOrAlias interface{}) M
- func Unset(spec interface{}) M
- func Where(js primitive.JavaScript) M
- type NearLegacyOperator
- type NearOperator
- type NearSphereLegacyOperator
- type NearSphereOperator
- type TextOperator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EachModifier ¶
type EachModifier M
EachModifier returned from Each
func Each ¶
func Each(value interface{}) EachModifier
Each modifies the $push and $addToSet operators to append multiple items for array updates. https://docs.mongodb.com/manual/reference/operator/update/each/
func (EachModifier) Position ¶
func (m EachModifier) Position(at int) EachModifier
Position modifier specifies the location in the array at which the $push operator inserts elements. Without the $position modifier, the $push operator inserts elements to the end of the array. https://docs.mongodb.com/manual/reference/operator/update/position/
func (EachModifier) Slice ¶
func (m EachModifier) Slice(num int) EachModifier
Slice modifier limits the number of array elements during a $push operation. https://docs.mongodb.com/manual/reference/operator/update/slice/
func (EachModifier) Sort ¶
func (m EachModifier) Sort(sort interface{}) EachModifier
Sort modifier orders the elements of an array during a $push operation. https://docs.mongodb.com/manual/reference/operator/update/sort/
type GeometryOperator ¶
type GeometryOperator M
GeometryOperator returned from Geometry
func Geometry ¶
func Geometry(typ string, coordinates interface{}) GeometryOperator
Geometry specifies a geometry in GeoJSON format to geospatial query operators. https://docs.mongodb.com/manual/reference/operator/query/geometry/
func (GeometryOperator) SetCRS ¶
func (op GeometryOperator) SetCRS(v interface{}) GeometryOperator
SetCRS option
type M ¶
M alias primitive.M
func AddToSet ¶
func AddToSet(spec interface{}) M
AddToSet adds elements to an array only if they do not already exist in the set. https://docs.mongodb.com/manual/reference/operator/update/addToSet/
func All ¶
func All(value interface{}) M
All selects the documents where the value of a field is an array that contains all the specified elements. https://docs.mongodb.com/manual/reference/operator/query/all/
func And ¶
func And(expr ...interface{}) M
And joins query clauses with a logical AND returns all documents that match the conditions of both clauses. https://docs.mongodb.com/manual/reference/operator/query/and/
func Bit ¶
func Bit(spec interface{}) M
Bit performs a bitwise update of a field. The operator supports bitwise and, bitwise or, and bitwise xor (i.e. exclusive or) operations. https://docs.mongodb.com/manual/reference/operator/update/bit/
func BitsAllClear ¶
func BitsAllClear(mask interface{}) M
BitsAllClear matches documents where all of the bit positions given by the query are clear (i.e. 0) in field. New in version 3.2. https://docs.mongodb.com/manual/reference/operator/query/bitsAllClear/
func BitsAllSet ¶
func BitsAllSet(mask interface{}) M
BitsAllSet matches documents where all of the bit positions given by the query are set (i.e. 1) in field. New in version 3.2. https://docs.mongodb.com/manual/reference/operator/query/bitsAllSet/
func BitsAnyClear ¶
func BitsAnyClear(mask interface{}) M
BitsAnyClear matches documents where all of the bit positions given by the query are clear (i.e. 0) in field. New in version 3.2. https://docs.mongodb.com/manual/reference/operator/query/bitsAllClear/
func BitsAnySet ¶
func BitsAnySet(mask interface{}) M
BitsAnySet matches documents where any of the bit positions given by the query are set (i.e. 1) in field. New in version 3.2. https://docs.mongodb.com/manual/reference/operator/query/bitsAllSet/
func Box ¶
Box specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. https://docs.mongodb.com/manual/reference/operator/query/box/
func Center ¶
Center specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. https://docs.mongodb.com/manual/reference/operator/query/center/
func CenterSphere ¶
CenterSphere specifies a circle using either legacy coordinate pairs or GeoJSON format for $geoWithin queries when using spherical geometry. The 2dsphere and 2d indexes support $centerSphere. https://docs.mongodb.com/manual/reference/operator/query/centerSphere/
func Comment ¶ added in v0.3.2
Comment Adds a comment to a query predicate. https://docs.mongodb.com/manual/reference/operator/query/comment/
func CurrentDate ¶
func CurrentDate(spec interface{}) M
CurrentDate sets the value of a field to current date, either as a Date or a Timestamp. https://docs.mongodb.com/manual/reference/operator/update/currentDate/
func ElemMatch ¶
func ElemMatch(query interface{}) M
ElemMatch matches documents that contain an array field with at least one element that matches all the specified query criteria. https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
func Eq ¶
func Eq(value interface{}) M
Eq matches values that are equal to a specified value. https://docs.mongodb.com/manual/reference/operator/query/eq
func Exists ¶
Exists matches documents that have the specified field. https://docs.mongodb.com/manual/reference/operator/query/exists/
func Explain ¶ added in v0.3.2
func Explain() M
Explain provides information on the query plan. It returns a document that describes the process and indexes used to return the query. This may provide useful insight when attempting to optimize a query. https://docs.mongodb.com/manual/reference/operator/meta/explain/
func Expr ¶
func Expr(expr interface{}) M
Expr allows use of aggregation expressions within the query language. https://docs.mongodb.com/manual/reference/operator/query/expr/
func FirstElemMatch ¶
func FirstElemMatch(spec interface{}) M
FirstElemMatch the first element in an array that matches the specified $elemMatch condition https://docs.mongodb.com/manual/reference/operator/projection/elemMatch/
func GeoIntersects ¶
func GeoIntersects(geometry interface{}) M
GeoIntersects selects documents whose geospatial data intersects with a specified GeoJSON object; i.e. where the intersection of the data and the specified object is non-empty. https://docs.mongodb.com/manual/reference/operator/query/geoIntersects/
func GeoWithIn ¶
func GeoWithIn(geometry interface{}) M
GeoWithIn selects documents with geospatial data that exists entirely within a specified shape. https://docs.mongodb.com/manual/reference/operator/query/geoWithin/
func Gt ¶
func Gt(value interface{}) M
Gt matches values that are greater than a specified value. https://docs.mongodb.com/manual/reference/operator/query/gt
func Gte ¶
func Gte(value interface{}) M
Gte matches values that are greater than or equal to a specified value. https://docs.mongodb.com/manual/reference/operator/query/gte/
func Hint ¶ added in v0.3.2
func Hint(hint interface{}) M
Hint operator forces the query optimizer to use a specific index to fulfill the query. Specify the index either by the index name or by document. https://docs.mongodb.com/manual/reference/operator/meta/hint/
func In ¶
func In(value interface{}) M
In matches any of the values specified in an array. https://docs.mongodb.com/manual/reference/operator/query/in/
func Inc ¶
func Inc(spec interface{}) M
Inc increments the value of the field by the specified amount. https://docs.mongodb.com/manual/reference/operator/update/inc/
func JSONSchema ¶
func JSONSchema(schema interface{}) M
JSONSchema validate documents against the given JSON Schema. https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/
func Lt ¶
func Lt(value interface{}) M
Lt matches values that are less than a specified value. https://docs.mongodb.com/manual/reference/operator/query/lt/
func Lte ¶
func Lte(value interface{}) M
Lte matches values that are less than or equal to a specified value. https://docs.mongodb.com/manual/reference/operator/query/lte/
func Max ¶
func Max(spec interface{}) M
Max only updates the field if the specified value is greater than the existing field value. https://docs.mongodb.com/manual/reference/operator/update/max/
func MaxIndex ¶ added in v0.3.2
func MaxIndex(bound interface{}) M
MaxIndex specify the exclusive upper bound for a specific index in order to constrain the results of find(). The $max specifies the upper bound for all keys of a specific index in order. https://docs.mongodb.com/manual/reference/operator/meta/max/
func MaxTimeMS ¶ added in v0.3.2
MaxTimeMS specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/
func MergeOperators ¶ added in v0.3.0
MergeOperators in a last win manner. only merge top level fields.
func Meta ¶
Meta projects the document’s score assigned during $text operation.. https://docs.mongodb.com/manual/reference/operator/projection/meta/
func Min ¶
func Min(spec interface{}) M
Min only updates the field if the specified value is less than the existing field value. https://docs.mongodb.com/manual/reference/operator/update/min/
func MinIndex ¶ added in v0.3.2
func MinIndex(bound interface{}) M
MinIndex specify a $min value to specify the inclusive lower bound for a specific index in order to constrain the results of find(). The $min specifies the lower bound for all keys of a specific index in order. https://docs.mongodb.com/manual/reference/operator/meta/min/
func Mod ¶
Mod performs a modulo operation on the value of a field and selects documents with a specified result. https://docs.mongodb.com/manual/reference/operator/query/mod/
func Mul ¶
func Mul(spec interface{}) M
Mul multiplies the value of the field by the specified amount. https://docs.mongodb.com/manual/reference/operator/update/mul/
func Natural ¶ added in v0.3.2
Natural use in conjunction with cursor.hint() to perform a collection scan to return documents in natural order. https://docs.mongodb.com/manual/reference/operator/meta/natural/
func Ne ¶
func Ne(value interface{}) M
Ne matches all values that are not equal to a specified value. https://docs.mongodb.com/manual/reference/operator/query/ne/
func Nin ¶
func Nin(value interface{}) M
Nin matches none of the values specified in an array. https://docs.mongodb.com/manual/reference/operator/query/nin/
func Nor ¶
func Nor(expr ...interface{}) M
Nor inverts the effect of a query expression and returns documents that do not match the query expression. https://docs.mongodb.com/manual/reference/operator/query/nor/
func Not ¶
func Not(expr interface{}) M
Not inverts the effect of a query expression and returns documents that do not match the query expression. https://docs.mongodb.com/manual/reference/operator/query/not/
func Or ¶
func Or(expr ...interface{}) M
Or joins query clauses with a logical OR returns all documents that match the conditions of either clause. https://docs.mongodb.com/manual/reference/operator/query/or/
func OrderBy ¶ added in v0.3.2
func OrderBy(sort interface{}) M
OrderBy sorts the results of a query in ascending or descending order. https://docs.mongodb.com/manual/reference/operator/meta/orderby/
func Polygon ¶
Polygon specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. https://docs.mongodb.com/manual/reference/operator/query/polygon/
func Pop ¶
func Pop(spec interface{}) M
Pop removes the first or last element of an array. Pass a value of -1 to remove the first element of an array and 1 to remove the last element in an array. https://docs.mongodb.com/manual/reference/operator/update/pop/
func Pull ¶
func Pull(spec interface{}) M
Pull removes from an existing array all instances of a value or values that match a specified condition. https://docs.mongodb.com/manual/reference/operator/update/pull/
func PullAll ¶
func PullAll(spec interface{}) M
PullAll removes all instances of the specified values from an existing array. Unlike the $pull operator that removes elements by specifying a query, $pullAll removes elements that match the listed values. https://docs.mongodb.com/manual/reference/operator/update/pullAll/
func Push ¶
func Push(spec interface{}) M
Push appends a specified value to an array. https://docs.mongodb.com/manual/reference/operator/update/push/
func Query ¶ added in v0.3.2
func Query(expr interface{}) M
Query operator forces MongoDB to interpret an expression as a query. https://docs.mongodb.com/manual/reference/operator/meta/query/
func Rand ¶ added in v0.3.2
func Rand() M
Rand generates a random float between 0 and 1. https://docs.mongodb.com/manual/reference/operator/query/rand/
func Regex ¶
Regex selects documents where values match a specified regular expression. https://docs.mongodb.com/manual/reference/operator/query/regex/
func Rename ¶
func Rename(spec interface{}) M
Rename updates the name of a field. https://docs.mongodb.com/manual/reference/operator/update/rename/
func ReturnKey ¶ added in v0.3.2
func ReturnKey() M
ReturnKey only return the index field or fields for the results of the query. If $returnKey is set to true and the query does not use an index to perform the read operation, the returned documents will not contain any fields https://docs.mongodb.com/manual/reference/operator/meta/returnKey/
func Set ¶
func Set(spec interface{}) M
Set the value of a field in a document. https://docs.mongodb.com/manual/reference/operator/update/set/
func SetOnInsert ¶
func SetOnInsert(spec interface{}) M
SetOnInsert sets the value of a field if an update results in an insert of a document. Has no effect on update operations that modify existing documents. https://docs.mongodb.com/manual/reference/operator/update/setOnInsert/
func ShowDiskLoc ¶ added in v0.3.2
func ShowDiskLoc() M
ShowDiskLoc adds a field $diskLoc to the returned documents. The value of the added $diskLoc field is a document that contains the disk location information:
"$diskLoc": { "file": <int>, "offset": <int> }
https://docs.mongodb.com/manual/reference/operator/meta/showDiskLoc/
func Size ¶
Size matches any array with the number of elements specified by the argument. https://docs.mongodb.com/manual/reference/operator/query/size/
func SliceN ¶
SliceN limits the number of elements projected from an array https://docs.mongodb.com/manual/reference/operator/projection/slice/
func SliceSkip ¶
Slice limits the number of elements projected from an array. use skip and limit syntax. https://docs.mongodb.com/manual/reference/operator/projection/slice/
func Type ¶
func Type(numberOrAlias interface{}) M
Type selects documents if a field is of the specified type. Changed in version 3.2. https://docs.mongodb.com/manual/reference/operator/query/type/
func Unset ¶
func Unset(spec interface{}) M
Unset removes the specified field from a document. https://docs.mongodb.com/manual/reference/operator/update/unset/
func Where ¶
func Where(js primitive.JavaScript) M
Where matches documents that satisfy a JavaScript expression.
type NearLegacyOperator ¶
type NearLegacyOperator M
NearLegacyOperator returned from NearLegacy.
func NearLegacy ¶
func NearLegacy(x, y float64) NearLegacyOperator
NearLegacy specify a point using legacy coordinates. https://docs.mongodb.com/manual/reference/operator/query/near/
func (NearLegacyOperator) SetMaxDistance ¶
func (op NearLegacyOperator) SetMaxDistance(meters float64) NearLegacyOperator
SetMaxDistance option
type NearOperator ¶
type NearOperator M
NearOperator returned from Near.
func Near ¶
func Near(longitude, latitude float64) NearOperator
Near returns geospatial objects in proximity to a point. Requires a geospatial index. https://docs.mongodb.com/manual/reference/operator/query/near/
func (NearOperator) SetMaxDistance ¶
func (op NearOperator) SetMaxDistance(meters float64) NearOperator
SetMaxDistance option
func (NearOperator) SetMinDistance ¶
func (op NearOperator) SetMinDistance(meters float64) NearOperator
SetMinDistance option
type NearSphereLegacyOperator ¶
type NearSphereLegacyOperator M
NearSphereLegacyOperator returned from NearLegacy.
func NearSphereLegacy ¶
func NearSphereLegacy(x, y float64) NearSphereLegacyOperator
NearSphereLegacy specify a point using legacy coordinates. https://docs.mongodb.com/manual/reference/operator/query/nearSphere/
func (NearSphereLegacyOperator) SetMaxDistance ¶
func (op NearSphereLegacyOperator) SetMaxDistance(meters float64) NearSphereLegacyOperator
SetMaxDistance option
func (NearSphereLegacyOperator) SetMinDistance ¶
func (op NearSphereLegacyOperator) SetMinDistance(meters float64) NearSphereLegacyOperator
SetMinDistance option
type NearSphereOperator ¶
type NearSphereOperator M
NearSphereOperator returned from NearSphere.
func NearSphere ¶
func NearSphere(longitude, latitude float64) NearSphereOperator
NearSphere returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. https://docs.mongodb.com/manual/reference/operator/query/nearSphere/
func (NearSphereOperator) SetMaxDistance ¶
func (op NearSphereOperator) SetMaxDistance(meters int) NearSphereOperator
SetMaxDistance option
func (NearSphereOperator) SetMinDistance ¶
func (op NearSphereOperator) SetMinDistance(meters int) NearSphereOperator
SetMinDistance option
type TextOperator ¶
type TextOperator M
TextOperator returned by Text
func Text ¶
func Text(search string) TextOperator
Text performs text search. https://docs.mongodb.com/manual/reference/operator/query/text/
func (TextOperator) SetCaseSensitive ¶
func (op TextOperator) SetCaseSensitive(v bool) TextOperator
SetCaseSensitive option
func (TextOperator) SetDiacriticSensitive ¶
func (op TextOperator) SetDiacriticSensitive(v bool) TextOperator
SetDiacriticSensitive option
func (TextOperator) SetLanguage ¶
func (op TextOperator) SetLanguage(v string) TextOperator
SetLanguage option