Documentation ¶
Index ¶
- Constants
- type ArrayField
- func (f ArrayField) ArrayContainsAll(val ...any) Expression
- func (f ArrayField) ArrayContainsElement(queries ...QueryOperator) Expression
- func (f ArrayField) ArrayContainsElementMatchesExpression(expressions ...Expression) Expression
- func (f ArrayField) ArrayContainsExact(val ...any) Expression
- func (f ArrayField) ArraySize(size int) Expression
- type Expression
- type Field
- func (f Field) CurrentDate() UpdateExpression
- func (f Field) Equals(value any) Expression
- func (f Field) Exists() Expression
- func (f Field) GreaterThan(value any) Expression
- func (f Field) GreaterThanOrEquals(value any) Expression
- func (f Field) Gt(value any) Expression
- func (f Field) Gte(value any) Expression
- func (f Field) In(value ...any) Expression
- func (f Field) Inc(value any) UpdateExpression
- func (f Field) LessThan(value any) Expression
- func (f Field) LessThanOrEqual(value any) Expression
- func (f Field) Lt(value any) Expression
- func (f Field) Lte(value any) Expression
- func (f Field) Max(value any) UpdateExpression
- func (f Field) Min(value any) UpdateExpression
- func (f Field) Mul(value any) UpdateExpression
- func (f Field) Ne(value any) Expression
- func (f Field) NotEquals(value any) Expression
- func (f Field) NotExists() Expression
- func (f Field) NotIn(value ...any) Expression
- func (f Field) Regex(val string, opts ...RegexpOption) Expression
- func (f Field) Rename(value Field) UpdateExpression
- func (f Field) Set(value any) UpdateExpression
- func (f Field) Unset() UpdateExpression
- type LogicalOperator
- type QueryOperator
- func All(val ...any) QueryOperator
- func Equals(value any) QueryOperator
- func Exists() QueryOperator
- func Gt(value any) QueryOperator
- func Gte(value any) QueryOperator
- func In(value ...any) QueryOperator
- func Lt(value any) QueryOperator
- func Lte(value any) QueryOperator
- func Ne(value any) QueryOperator
- func NotExists() QueryOperator
- func NotIn(value ...any) QueryOperator
- func Regex(val string) QueryOperator
- func Size(size int) QueryOperator
- type RegexpOption
- type UpdateExpression
- type UpdateOperator
Examples ¶
Constants ¶
const RegexpOptionCaseInsensitivity = RegexpOption("i")
RegexpOptionCaseInsensitivity case insensitivity to match upper and lower cases.
const RegexpOptionExtended = RegexpOption("x")
RegexpOptionExtended defines "extended" capability to ignore all white space characters in the pattern unless escaped or included in a character class. Additionally, it ignores characters in-between and including an un-escaped hash/pound (#) character and the next new line, so that you may include comments in complicated patterns. This only applies to data characters; white space characters may never appear within special character sequences in a pattern.
The x option does not affect the handling of the VT character (i.e. code 11).
const RegexpOptionMatchAll = RegexpOption("s")
RegexpOptionMatchAll allows the dot character (i.e. .) to match all characters including newline characters.
const RegexpOptionMultiline = RegexpOption("M")
RegexpOptionMultiline is for patterns that include anchors (i.e. ^ for the start, $ for the end), match at the beginning or end of each line for strings with multiline values. Without this option, these anchors match at beginning or end of the string. For an example, see Multiline Match for Lines Starting with Specified Pattern.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayField ¶
type ArrayField string
ArrayField represents an array field in a BSON document.
func (ArrayField) ArrayContainsAll ¶
func (f ArrayField) ArrayContainsAll(val ...any) Expression
ArrayContainsAll matches all documents where the given values are in the array.
func (ArrayField) ArrayContainsElement ¶
func (f ArrayField) ArrayContainsElement(queries ...QueryOperator) Expression
func (ArrayField) ArrayContainsElementMatchesExpression ¶
func (f ArrayField) ArrayContainsElementMatchesExpression(expressions ...Expression) Expression
ArrayContainsElementMatchesExpression matches all documents which meet the EXACT expression.
func (ArrayField) ArrayContainsExact ¶
func (f ArrayField) ArrayContainsExact(val ...any) Expression
ArrayContainsExact matches all documents where ONLY the given values are in the array.
func (ArrayField) ArraySize ¶
func (f ArrayField) ArraySize(size int) Expression
type Expression ¶
type Expression struct {
// contains filtered or unexported fields
}
Expression represents a MongoDB Expression for a specific field.
func (Expression) And ¶
func (e Expression) And(e2 ...Expression) Expression
And represents a logical query operation for 'and' condition. It takes one or more Expression(s) and selects the documents that satisfy all the expressions.
Example ¶
Filter := struct { Status Field Size struct { H Field Uom Field } }{ Status: Field("status"), Size: struct { H Field Uom Field }{ Uom: Field("size.uom"), H: Field("size.h"), }, } f1 := Filter.Size.H.Lt(15).And(Filter.Size.Uom.Equals("in")) fmt.Println(f1)
Output: bson.D{{"$and", []bson.D{bson.D{{"size.h", bson.D{{"$lt", 15}}}}, bson.D{{"size.uom", "in"}}}}}
Example (WithEquals) ¶
Filter := struct { Status Field Size struct { H Field Uom Field } }{ Status: Field("status"), Size: struct { H Field Uom Field }{ Uom: Field("size.uom"), H: Field("size.h"), }, } f1 := Filter.Size.H.Lt(15).And(Filter.Size.Uom.Equals("in"), Filter.Status.Equals("D")) fmt.Println(f1)
Output: bson.D{{"$and", []bson.D{bson.D{{"size.h", bson.D{{"$lt", 15}}}}, bson.D{{"size.uom", "in"}}, bson.D{{"status", "D"}}}}}
func (Expression) MarshalBSON ¶
func (e Expression) MarshalBSON() ([]byte, error)
MarshalBSON serializes the Expression to BSON data.
func (Expression) Or ¶
func (e Expression) Or(e2 ...Expression) Expression
Or represents a logical query operation for 'or' condition. It takes one or more Expression(s) and selects the documents that satisfy at least one expression.
Example ¶
Filter := struct { Status Field Size struct { H Field Uom Field } }{ Status: Field("status"), Size: struct { H Field Uom Field }{ Uom: Field("size.uom"), H: Field("size.h"), }, } f1 := Filter.Size.H.Lt(15).Or(Filter.Size.Uom.Equals("in")) fmt.Println(f1)
Output: bson.D{{"$or", []bson.D{bson.D{{"size.h", bson.D{{"$lt", 15}}}}, bson.D{{"size.uom", "in"}}}}}
func (Expression) String ¶
func (e Expression) String() string
type Field ¶
type Field string
Field represents a single field in a BSON document.
func (Field) CurrentDate ¶
func (f Field) CurrentDate() UpdateExpression
CurrentDate sets the value of a field to the current date, either as a Date or a timestamp.
func (Field) Equals ¶
func (f Field) Equals(value any) Expression
Equals represents a query operation for 'equals' comparison.
Example ¶
Filter := struct { Size struct { Uom Field } }{ Size: struct { Uom Field }{ Uom: Field("size.uom"), }, } f1 := Filter.Size.Uom.Equals("in") fmt.Println(f1)
Output: bson.D{{"size.uom", "in"}}
func (Field) Exists ¶
func (f Field) Exists() Expression
Exists represents an element query operation to check if a field exists. It Matches documents that have the specified field.
func (Field) GreaterThan ¶
func (f Field) GreaterThan(value any) Expression
GreaterThan represents a query operation for 'greater than' comparison.
func (Field) GreaterThanOrEquals ¶
func (f Field) GreaterThanOrEquals(value any) Expression
GreaterThanOrEquals represents a query operation for 'greater than or equals' comparison.
func (Field) Gt ¶
func (f Field) Gt(value any) Expression
Gt represents a query operation for 'greater than' comparison.
func (Field) Gte ¶
func (f Field) Gte(value any) Expression
Gte represents a query operation for 'greater than or equals' comparison.
func (Field) In ¶
func (f Field) In(value ...any) Expression
In represents a query operation for 'in' comparison. The operator selects the documents where the value of a field equals any value in the specified parameter(s).
func (Field) Inc ¶
func (f Field) Inc(value any) UpdateExpression
Inc increments the field by a specified value.
func (Field) LessThan ¶
func (f Field) LessThan(value any) Expression
LessThan represents a query operation for 'less than' comparison.
func (Field) LessThanOrEqual ¶
func (f Field) LessThanOrEqual(value any) Expression
LessThanOrEqual represents a query operation for 'less than or equals' comparison.
func (Field) Lt ¶
func (f Field) Lt(value any) Expression
Lt represents a query operation for 'less than' comparison.
Example ¶
Filter := struct { Size struct { H Field } }{ Size: struct { H Field }{ H: Field("size.h"), }, } f1 := Filter.Size.H.Lt(15) fmt.Println(f1)
Output: bson.D{{"size.h", bson.D{{"$lt", 15}}}}
func (Field) Lte ¶
func (f Field) Lte(value any) Expression
Lte represents a query operation for 'less than or equal' comparison.
func (Field) Max ¶
func (f Field) Max(value any) UpdateExpression
Max updates the value of the field to a specified value if the specified value is greater than the current value of the field.
The '$max operator', which is used internally, can compare values of different types, using the BSON comparison order.
func (Field) Min ¶
func (f Field) Min(value any) UpdateExpression
Min updates the value of the field to a specified value if the specified value is less than the current value of the field.
The '$min operator', which is used internally, can compare values of different types, using the BSON comparison order.
func (Field) Mul ¶
func (f Field) Mul(value any) UpdateExpression
Mul multiplies the value of the field by a number.
The field to update must contain a numeric value.
func (Field) Ne ¶
func (f Field) Ne(value any) Expression
Ne represents a query operation for 'not equals' comparison.
func (Field) NotEquals ¶
func (f Field) NotEquals(value any) Expression
NotEquals represents a query operation for 'not equals' comparison.
func (Field) NotExists ¶
func (f Field) NotExists() Expression
NotExists represents an element query operation to check if a field does not exist. It Matches documents that do not have the specified field.
func (Field) NotIn ¶
func (f Field) NotIn(value ...any) Expression
NotIn represents a query operation for 'not in' comparison. The operator selects the documents where:
- the specified field value is not in the specified array or
- the specified field does not exist.
func (Field) Regex ¶
func (f Field) Regex(val string, opts ...RegexpOption) Expression
Regex represents an element query operation which has regular expression capabilities for pattern matching strings in queries.
Example ¶
Filter := struct { Status Field Size struct { H Field Uom Field } }{ Status: Field("status"), Size: struct { H Field Uom Field }{ Uom: Field("size.uom"), H: Field("size.h"), }, } f1 := Filter.Size.Uom.Regex("i.*") fmt.Println(f1)
Output: bson.D{{"size.uom", bson.D{{"$regex", "i.*"}}}}
Example (WithOptions) ¶
Filter := struct { Status Field Size struct { H Field Uom Field } }{ Status: Field("status"), Size: struct { H Field Uom Field }{ Uom: Field("size.uom"), H: Field("size.h"), }, } f1 := Filter.Size.Uom.Regex("i.*", RegexpOptionCaseInsensitivity) fmt.Println(f1)
Output: bson.D{{"size.uom", bson.D{{"$regex", "i.*"},{"$options", "i"}}}}
func (Field) Rename ¶
func (f Field) Rename(value Field) UpdateExpression
Rename updates the name of the field.
The new field name must differ from the existing field name.
func (Field) Set ¶
func (f Field) Set(value any) UpdateExpression
Set replaces the value of the field with the specified value.
Example ¶
expression := Listing.ListingUrl.Set("http://www.source-fellows.com") fmt.Println(expression)
Output: bson.D{{"$set", bson.D{{"listing_url", "http://www.source-fellows.com"}}}}
Example (WithCondition) ¶
expression := Listing.ListingUrl.Set("http://www.source-fellows.com").And(Listing.Name.Set("Horst")) fmt.Println(expression)
Output: bson.D{{"$set", bson.D{{"listing_url", "http://www.source-fellows.com"},{"name", "Horst"}}}}
type LogicalOperator ¶
type LogicalOperator struct {
// contains filtered or unexported fields
}
LogicalOperator is used to represent a logical MongoDB Operator.
type QueryOperator ¶
type QueryOperator struct {
// contains filtered or unexported fields
}
QueryOperator is used to represent a MongoDB Query Operator.
func All ¶
func All(val ...any) QueryOperator
All builds a simple QueryOperator for MongoDB operator "$all". "all"
func Equals ¶
func Equals(value any) QueryOperator
Equals builds a simple QueryOperator for MongoDB operator "$eq".
func Exists ¶
func Exists() QueryOperator
Exists builds a simple QueryOperator for MongoDB operator "$exists". "exists"
func Gt ¶
func Gt(value any) QueryOperator
Gt builds a simple QueryOperator for MongoDB operator "$gt".
func Gte ¶
func Gte(value any) QueryOperator
Gte builds a simple QueryOperator for MongoDB operator "$gte". "greater or equals"
func In ¶
func In(value ...any) QueryOperator
In builds a simple QueryOperator for MongoDB operator "$in". "in"
func Lt ¶
func Lt(value any) QueryOperator
Lt builds a simple QueryOperator for MongoDB operator "$lt". "Less than"
func Lte ¶
func Lte(value any) QueryOperator
Lte builds a simple QueryOperator for MongoDB operator "$lte". "Less than or equals"
func Ne ¶
func Ne(value any) QueryOperator
Ne builds a simple QueryOperator for MongoDB operator "$ne". "not equals"
func NotExists ¶
func NotExists() QueryOperator
NotExists builds a simple QueryOperator for MongoDB operator "$exists". "not exists"
func NotIn ¶
func NotIn(value ...any) QueryOperator
NotIn builds a simple QueryOperator for MongoDB operator "$nin". "in"
func Regex ¶
func Regex(val string) QueryOperator
Regex buidls a regular expression capabilities for pattern matching strings in queries.
func Size ¶
func Size(size int) QueryOperator
Size builds a simple QueryOperator for MongoDB operator "$size". "size of array"
type RegexpOption ¶
type RegexpOption string
type UpdateExpression ¶
type UpdateExpression struct {
// contains filtered or unexported fields
}
func (UpdateExpression) And ¶
func (ue UpdateExpression) And(ue2 ...UpdateExpression) UpdateExpression
func (UpdateExpression) MarshalBSON ¶
func (ue UpdateExpression) MarshalBSON() ([]byte, error)
func (UpdateExpression) String ¶
func (ue UpdateExpression) String() string
type UpdateOperator ¶
type UpdateOperator struct {
// contains filtered or unexported fields
}
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
examples
|
|
generator/filter
Code generated by monGo-Query.
|
Code generated by monGo-Query. |