Documentation
¶
Index ¶
- Constants
- type Builder
- func (qb *Builder) AddStage(stage bsonV2.D) *Builder
- func (qb *Builder) Build() (bsonV2.M, *optionsV2.FindOptions)
- func (qb *Builder) BuildFind() (interface{}, optionsV2.Lister[optionsV2.FindOptions], error)
- func (qb *Builder) BuildFindOne() (interface{}, optionsV2.Lister[optionsV2.FindOneOptions], error)
- func (qb *Builder) BuildPipeline() []bsonV2.D
- func (qb *Builder) SetAll(field string, values []interface{}) *Builder
- func (qb *Builder) SetAnd(conditions []bsonV2.M) *Builder
- func (qb *Builder) SetBetween(field string, start, end interface{}) *Builder
- func (qb *Builder) SetCurrentDate(field string) *Builder
- func (qb *Builder) SetElemMatch(field string, match bsonV2.M) *Builder
- func (qb *Builder) SetExists(field string, exists bool) *Builder
- func (qb *Builder) SetFilter(filter bsonV2.M) *Builder
- func (qb *Builder) SetGeoIntersects(field string, geometry bsonV2.M) *Builder
- func (qb *Builder) SetGeoWithin(field string, geometry bsonV2.M) *Builder
- func (qb *Builder) SetGreaterThan(field string, value interface{}) *Builder
- func (qb *Builder) SetIn(field string, values []interface{}) *Builder
- func (qb *Builder) SetLessThan(field string, value interface{}) *Builder
- func (qb *Builder) SetLimit(limit int64) *Builder
- func (qb *Builder) SetMod(field string, divisor, remainder int) *Builder
- func (qb *Builder) SetNear(field string, point bsonV2.M, maxDistance, minDistance float64) *Builder
- func (qb *Builder) SetNearSphere(field string, point bsonV2.M, maxDistance, minDistance float64) *Builder
- func (qb *Builder) SetNotEqual(field string, value interface{}) *Builder
- func (qb *Builder) SetNotIn(field string, values []interface{}) *Builder
- func (qb *Builder) SetOr(conditions []bsonV2.M) *Builder
- func (qb *Builder) SetPage(page, size int64) *Builder
- func (qb *Builder) SetProjection(projection bsonV2.M) *Builder
- func (qb *Builder) SetRegex(field string, pattern string, options string) *Builder
- func (qb *Builder) SetSize(field string, size int) *Builder
- func (qb *Builder) SetSkip(skip int64) *Builder
- func (qb *Builder) SetSkipLimit(offset, limit int64) *Builder
- func (qb *Builder) SetSort(sort bsonV2.D) *Builder
- func (qb *Builder) SetSortWithPriority(sortFields []bsonV2.E) *Builder
- func (qb *Builder) SetTextSearch(search string) *Builder
- func (qb *Builder) SetTokenPagination(token string, pageSize int64) *Builder
- func (qb *Builder) SetType(field string, typeValue interface{}) *Builder
- func (qb *Builder) Where(cond bsonV2.M) *Builder
Constants ¶
const ( OperatorEq = "$eq" // 等于 OperatorNe = "$ne" // 不等于 OperatorGt = "$gt" // 大于 OperatorGte = "$gte" // 大于等于 OperatorLt = "$lt" // 小于 OperatorLte = "$lte" // 小于等于 OperatorAnd = "$and" // 与 OperatorOr = "$or" // 或 OperatorNot = "$not" // 非 OperatorNor = "$nor" // 非或 OperatorExists = "$exists" // 是否存在 OperatorType = "$type" // 类型 OperatorExpr = "$expr" // 表达式 OperatorJsonSchema = "$jsonSchema" // JSON Schema 验证 OperatorMod = "$mod" // 取模 OperatorRegex = "$regex" // 正则表达式 OperatorText = "$text" // 文本搜索 OperatorWhere = "$where" // JavaScript 表达式 OperatorSearch = "$search" // 文本搜索 OperatorAll = "$all" // 匹配所有 OperatorElemMatch = "$elemMatch" // 匹配数组中的元素 OperatorSize = "$size" // 数组大小 OperatorIn = "$in" // 包含 OperatorNin = "$nin" // 不包含 OperatorSet = "$set" // 设置字段值 OperatorUnset = "$unset" // 删除字段 OperatorInc = "$inc" // 增加值 OperatorMul = "$mul" // 乘法 OperatorRename = "$rename" // 重命名字段 OperatorCurrentDate = "$currentDate" // 设置当前日期 OperatorAddToSet = "$addToSet" // 添加到集合 OperatorPop = "$pop" // 删除数组中的元素 OperatorPull = "$pull" // 删除匹配的数组元素 OperatorPush = "$push" // 添加数组元素 OperatorEach = "$each" // 批量添加数组元素 OperatorSlice = "$slice" // 截取数组 OperatorSort = "$sort" // 排序数组 OperatorPosition = "$position" // 指定数组位置 OperatorGroup = "$group" // 分组 OperatorMatch = "$match" // 匹配 OperatorProject = "$project" // 投影 OperatorSortAgg = "$sort" // 排序 OperatorLimit = "$limit" // 限制 OperatorSkip = "$skip" // 跳过 OperatorUnwind = "$unwind" // 拆分数组 OperatorLookup = "$lookup" // 关联查询 OperatorAddFields = "$addFields" // 添加字段 OperatorReplaceRoot = "$replaceRoot" // 替换根字段 OperatorCount = "$count" // 计数 OperatorFacet = "$facet" // 多面查询 OperatorBucket = "$bucket" // 分桶 OperatorBucketAuto = "$bucketAuto" // 自动分桶 OperatorIndexStats = "$indexStats" // 索引统计 OperatorOut = "$out" // 输出 OperatorMerge = "$merge" // 合并 OperatorSum = "$sum" // 求和 OperatorAvg = "$avg" // 平均值 OperatorMin = "$min" // 最小值 OperatorMax = "$max" // 最大值 OperatorFirst = "$first" // 第一个值 OperatorLast = "$last" // 最后一个值 OperatorStdDevPop = "$stdDevPop" // 总体标准差 OperatorStdDevSamp = "$stdDevSamp" // 样本标准差 OperatorToLong = "$toLong" // 转换为 long 类型 OperatorToDouble = "$toDouble" // 转换为 double 类型 OperatorToDecimal = "$toDecimal" // 转换为 decimal 类型 OperatorToString = "$toString" // 转换为 string 类型 OperatorToDate = "$toDate" // 转换为 date 类型 OperatorToInt = "$toInt" // 转换为 int 类型 OperatorNear = "$near" // 查询距离某点最近的文档 OperatorNearSphere = "$nearSphere" // 查询距离某点最近的文档(球面距离) OperatorGeoWithin = "$geoWithin" // 地理范围查询 OperatorGeoIntersects = "$geoIntersects" // 地理相交查询 OperatorGeometry = "$geometry" // 几何图形 OperatorMaxDistance = "$maxDistance" // 最大距离 OperatorMinDistance = "$minDistance" // 最小距离 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder 用于构建 MongoDB 查询
func NewQueryBuilder ¶
func NewQueryBuilder() *Builder
func (*Builder) Build ¶
func (qb *Builder) Build() (bsonV2.M, *optionsV2.FindOptions)
Build 返回最终的过滤条件和查询选项
func (*Builder) BuildFind ¶
BuildFind 构建用于 Find 的 filter 与 options 返回值:filter interface{} (可为 bson.M/bson.D/...), options.Lister[options.FindOptions], error
func (*Builder) BuildFindOne ¶
BuildFindOne 构建用于 FindOne 的 filter 与 options 返回值:filter interface{} (可为 bson.M/bson.D/...), options.Lister[options.FindOneOptions], error
func (*Builder) BuildPipeline ¶
BuildPipeline 返回最终的聚合管道
func (*Builder) SetBetween ¶
SetBetween 设置字段的范围查询条件
func (*Builder) SetCurrentDate ¶
SetCurrentDate 设置字段为当前日期
func (*Builder) SetElemMatch ¶
SetElemMatch 设置数组字段的匹配条件
func (*Builder) SetGeoIntersects ¶
SetGeoIntersects 设置地理位置相交查询条件
func (*Builder) SetGeoWithin ¶
SetGeoWithin 设置地理位置范围查询条件
func (*Builder) SetGreaterThan ¶
SetGreaterThan 设置字段的大于条件
func (*Builder) SetLessThan ¶
SetLessThan 设置字段的小于条件
func (*Builder) SetNearSphere ¶
func (qb *Builder) SetNearSphere(field string, point bsonV2.M, maxDistance, minDistance float64) *Builder
SetNearSphere 设置球面距离附近查询条件
func (*Builder) SetNotEqual ¶
SetNotEqual 设置字段的不等于条件
func (*Builder) SetProjection ¶
SetProjection 设置查询结果的字段投影
func (*Builder) SetSkipLimit ¶
SetSkipLimit 设置 offset/limit(用于仓库中调用)
func (*Builder) SetSortWithPriority ¶
SetSortWithPriority 设置查询结果的排序条件,并指定优先级
func (*Builder) SetTextSearch ¶
SetTextSearch 设置文本搜索条件
func (*Builder) SetTokenPagination ¶
SetTokenPagination 保存 token 分页信息(供上层解析)