Documentation ¶
Index ¶
- Variables
- func Add(num, inc interface{}) interface{}
- func All(doc Doc, path string, compact, merge bool) (interface{}, bool)
- func Collect(list List, path string, compact, merge, flatten, distinct bool) bson.A
- func Compare(lv, rv interface{}) int
- func ConvertValue(v interface{}) (interface{}, error)
- func Decode(doc Doc, out interface{}) error
- func DecodeList(list List, out interface{}) error
- func Get(doc Doc, path string) interface{}
- func Increment(doc Doc, path string, increment interface{}) (interface{}, error)
- func IndexedPath(path string) bool
- func Mod(num, div interface{}) interface{}
- func Mul(num, mul interface{}) interface{}
- func Multiply(doc Doc, path string, multiplier interface{}) (interface{}, error)
- func MustConvertValue(v interface{}) interface{}
- func Now() primitive.Timestamp
- func Order(l, r Doc, columns []Column, identity bool) int
- func ParseIndex(str string) (int, bool)
- func PathSegment(path string) string
- func PathSegmentReverse(path string) string
- func Pick(list List, path string, compact bool) bson.A
- func Pop(doc Doc, path string, last bool) (interface{}, error)
- func Push(doc Doc, path string, value interface{}) (interface{}, error)
- func Put(doc Doc, path string, value interface{}, prepend bool) (interface{}, error)
- func ReducePath(path string) string
- func ReducePathReverse(path string) string
- func Sort(list List, columns []Column, identity bool)
- func Transfer(in, out interface{}) error
- func Unset(doc Doc, path string) interface{}
- type Class
- type Column
- type Doc
- type Index
- type List
- type MissingType
- type PathBuilder
- type PathNode
- type Schema
- type Set
Constants ¶
This section is empty.
Variables ¶
var Alias2Type = map[string]bsontype.Type{}
Alias2Type is a map from BSON type aliases to BSON types.
var ErrValidationFailed = fmt.Errorf("validation failed")
ErrValidationFailed is returned when the value failed to validate against the schema.
var Missing = MissingType{}
Missing represents the absence of a value in a document.
var Number2Type = map[byte]bsontype.Type{}
Number2Type is a map from BSON type numbers to BSON types.
var PathEnd = "\x00"
PathEnd is returned by X if the end of the path has been reached.
var Type2Alias = map[bsontype.Type]string{ bsontype.Double: "double", bsontype.String: "string", bsontype.EmbeddedDocument: "object", bsontype.Array: "array", bsontype.Binary: "binData", bsontype.Undefined: "undefined", bsontype.ObjectID: "objectId", bsontype.Boolean: "bool", bsontype.DateTime: "date", bsontype.Null: "null", bsontype.Regex: "regex", bsontype.DBPointer: "dbPointer", bsontype.JavaScript: "javascript", bsontype.Symbol: "symbol", bsontype.CodeWithScope: "javascriptWithScope", bsontype.Int32: "int", bsontype.Timestamp: "timestamp", bsontype.Int64: "long", bsontype.Decimal128: "decimal", bsontype.MinKey: "minKey", bsontype.MaxKey: "maxKey", }
Type2Alias is a map from BSON types to their alias.
Functions ¶
func Add ¶ added in v0.2.6
func Add(num, inc interface{}) interface{}
Add will add together two numerical values. It accepts and returns int32, int64, float64 and decimal128.
func All ¶
All has the basic behaviour as Get but additionally collects values from embedded documents in arrays. It returns and array and true if values from multiple documents, haven been collected. Missing values are skipped and intermediary arrays flattened if compact is set to true. By enabling merge, a resulting array of embedded document may be merged to on array containing all values.
func Collect ¶
Collect will get the value specified by path from each document and return a list of values. Different to Pick this function will also collect values from arrays of embedded documents. If compact is specified, Missing values are removed and intermediary arrays flattened. By enabling merge, a resulting array of embedded documents may be merged to on array containing all values. Flatten may flatten the resulting arrays per document to one array of values. Distinct may finally sort and remove duplicate values from the list.
func Compare ¶
func Compare(lv, rv interface{}) int
Compare will compare two bson values and return their order according to the BSON type comparison order specification: https://docs.mongodb.com/manual/reference/bson-type-comparison-order.
func ConvertValue ¶ added in v0.2.6
func ConvertValue(v interface{}) (interface{}, error)
ConvertValue will convert the provided type to a standard type.
func Decode ¶
Decode will decode the specified document to an arbitrary value which may be a struct with bson tags in most cases.
func DecodeList ¶
DecodeList will decode a list of documents to an arbitrary value.
func Get ¶
Get returns the value in the document specified by path. It returns Missing if the value has not been found. Dots may be used to descend into nested documents e.g. "foo.bar.baz" and numbers may be used to descend into arrays e.g. "foo.2.bar".
func Increment ¶
Increment will add the increment to the value at the location in the document specified by path and return the new value. If the value is missing, the increment is added to the document. The type of the field may be changed as part of the operation.
func IndexedPath ¶ added in v0.2.4
IndexedPath returns true if the specified path contains array indices.
func Mod ¶ added in v0.2.6
func Mod(num, div interface{}) interface{}
Mod will compute the modulo of the two values. It accepts and returns int32, in64, float64 and decimal128.
func Mul ¶ added in v0.2.6
func Mul(num, mul interface{}) interface{}
Mul will multiply the two numerical values. It accepts and returns int32, int64, float64 and decimal128.
func Multiply ¶
Multiply will multiply the multiplier with the value at the location in the document specified by path and return the new value. If the value is missing, a zero is added to the document. The type of the field may be changed as part of the operation.
func MustConvertValue ¶ added in v0.2.6
func MustConvertValue(v interface{}) interface{}
MustConvertValue will call ConvertValue and panic on errors.
func ParseIndex ¶ added in v0.2.0
ParseIndex will attempt to parse the provided string as an index.
func PathSegment ¶ added in v0.2.0
PathSegment will return the first segment of the path.
func PathSegmentReverse ¶ added in v0.2.3
PathSegmentReverse will return the last segment of the path.
func Pick ¶
Pick will get the value specified by path from each document and return a list of values. If compact is specified, Missing values are removed.
func Pop ¶ added in v0.2.0
Pop will remove the first or last element from the array at the location in the document specified byt path and return the updated array. If the array is empty, the value is missing or not an array, it will do nothing and return Missing.
func Push ¶ added in v0.1.9
Push will add the value to the array at the location in the document specified by path and return the new value. If the value is missing, the value is added to a new array.
func Put ¶
Put will store the value in the document at the location specified by path and return the previously stored value. It will automatically create document fields, array elements and embedded documents to fulfill the request. If prepends is set to true, new values are inserted at the beginning of the array or document. If the path contains a number e.g. "foo.1.bar" and no array exists at that levels, a document with the key "1" is created.
func ReducePath ¶ added in v0.2.3
ReducePath will reduce the path by one segment. It will return PathEnd if there are no more segments.
func ReducePathReverse ¶ added in v0.2.3
ReducePathReverse will reduce the path by one segment from the back. It will return PathEnd if there are no more segments.
func Transfer ¶
func Transfer(in, out interface{}) error
Transfer will transfer data from one type to another by marshalling the data and unmarshalling it again. This method is not very fast, but it ensures compatibility with custom types that implement the bson.Marshaller interface.
func Unset ¶
Unset will remove the value at the location in the document specified by path and return the previously stored value. If the path specifies an array element e.g. "foo.2" the element is nilled, but not removed from the array. This prevents unintentional effects through position shifts in the array.
Types ¶
type Class ¶
type Class int
Class is describes the class of one or more BSON types.
type Doc ¶
Doc is a full document that may contain fields, arrays and embedded documents. The pointer form is chosen to identify the document uniquely (pointer address).
func Clone ¶
Clone will clone the specified document. The returned document can be safely mutated without mutating the original document with one exception: the content of primitive.Binary values is not cloned and references the same byte slice as the original.
The function may panic if the doc is not obtained using Convert or Transform and contains unsupported types.
func Convert ¶
Convert will convert the provided value to a document. The value is expected to be a bson.M or bson.D composed of standard types.
func MustConvert ¶ added in v0.2.2
func MustConvert(v interface{}) Doc
MustConvert will call Convert and panic on errors.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is a basic btree based index for documents. The index is not safe from concurrent access.
func (*Index) Add ¶
Add will add the document to index. May return false if the document has already been added to the index.
func (*Index) Build ¶
Build will build the index from the specified list. It may return false if there was a unique constraint error when building the index. If an error is returned the index only has some documents added.
func (*Index) Clone ¶
Clone will clone the index. Mutating the new index will not mutate the original index.
type List ¶
type List = []Doc
List is consecutive list of documents.
func CloneList ¶
CloneList will clone a list of documents.
The function may panic if a doc is not obtained using Convert or Transform and contains unsupported types.
func ConvertList ¶ added in v0.2.0
ConvertList will convert an array to a list. The value is expected to be an array of bson.M or bson.D elements composed of standard types.
func MustConvertList ¶ added in v0.2.2
func MustConvertList(v interface{}) List
MustConvertList will call ConvertList and panic on errors.
func Select ¶
Select will return a list of documents selected by the specified selector. Limit may be specified to break early if the list reached the limit.
func TransformList ¶
TransformList will transform an arbitrary value info a list of documents composed of known primitives.
type PathBuilder ¶ added in v0.2.4
type PathBuilder struct {
// contains filtered or unexported fields
}
PathBuilder is a memory efficient builder for paths.
func NewPathBuilder ¶ added in v0.2.4
func NewPathBuilder(buffer int) *PathBuilder
NewPathBuilder creates a new path builder with the provided allocated memory.
func (*PathBuilder) AddIndex ¶ added in v0.2.4
func (b *PathBuilder) AddIndex(idx int) int
AddIndex will add the specified index.
func (*PathBuilder) AddSegment ¶ added in v0.2.4
func (b *PathBuilder) AddSegment(seg string) int
AddSegment will add the specified segment.
func (*PathBuilder) String ¶ added in v0.2.4
func (b *PathBuilder) String() string
String will return the built path.
func (*PathBuilder) Truncate ¶ added in v0.2.4
func (b *PathBuilder) Truncate(len int)
Truncate will shrink the buffer to the provided length.
type PathNode ¶ added in v0.2.4
type PathNode map[string]interface{}
PathNode is a node of a path tree.
func NewPathNode ¶ added in v0.2.4
func NewPathNode() PathNode
NewPathNode will return a new path node.
func (PathNode) Load ¶ added in v0.2.4
func (n PathNode) Load() interface{}
Load will return the currently stored value.
func (PathNode) Lookup ¶ added in v0.2.4
Lookup will traverse the path and return the last node. If the returned path is PathEnd the returned node is the final node.
type Schema ¶ added in v0.2.6
type Schema struct { // The schema document. Doc bson.D // The regex cache. Regexes map[string]*regexp.Regexp }
Schema implements the JSON Schema validation algorithm. Specifically, it implements the following specifications:
- https://docs.mongodb.com/manual/reference/operator/query/jsonSchema - https://tools.ietf.org/html/draft-zyp-json-schema-04 - https://tools.ietf.org/html/draft-fge-json-schema-validation-00
Note: The Go regex engine ist not ECMA 262 compatible as required by the draft.
type Set ¶
Set is set of unique documents. The set is not safe from concurrent access.
func (*Set) Add ¶
Add will add the document to set, if has not already been added. It may return false if the document has already been added.
func (*Set) Clone ¶
Clone will clone the set. Mutating the new set will not mutate the original set.