mongo-driver: go.mongodb.org/mongo-driver/x/bsonx Index | Examples | Files | Directories

package bsonx

import "go.mongodb.org/mongo-driver/x/bsonx"

Index

Examples

Package Files

array.go constructor.go document.go element.go mdocument.go primitive_codecs.go registry.go value.go

Variables

var DefaultRegistry = NewRegistryBuilder().Build()

DefaultRegistry is the default bsoncodec.Registry. It contains the default codecs and the primitive codecs.

var ErrNilArray = errors.New("array is nil")

ErrNilArray indicates that an operation was attempted on a nil *Array.

var ErrNilDocument = errors.New("document is nil")

ErrNilDocument indicates that an operation was attempted on a nil *bson.Document.

func NewRegistryBuilder Uses

func NewRegistryBuilder() *bsoncodec.RegistryBuilder

NewRegistryBuilder creates a new RegistryBuilder configured with the default encoders and deocders from the bsoncodec.DefaultValueEncoders and bsoncodec.DefaultValueDecoders types and the PrimitiveCodecs type in this package.

type Arr Uses

type Arr []Val

Arr represents an array in BSON.

func (Arr) Equal Uses

func (a Arr) Equal(a2 Arr) bool

Equal compares this document to another, returning true if they are equal.

func (Arr) MarshalBSONValue Uses

func (a Arr) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue implements the bsoncodec.ValueMarshaler interface.

func (Arr) String Uses

func (a Arr) String() string

String implements the fmt.Stringer interface.

func (*Arr) UnmarshalBSONValue Uses

func (a *Arr) UnmarshalBSONValue(t bsontype.Type, data []byte) error

UnmarshalBSONValue implements the bsoncodec.ValueUnmarshaler interface.

type Doc Uses

type Doc []Elem

Doc is a type safe, concise BSON document representation.

func ReadDoc Uses

func ReadDoc(b []byte) (Doc, error)

ReadDoc will create a Document using the provided slice of bytes. If the slice of bytes is not a valid BSON document, this method will return an error.

func (Doc) Append Uses

func (d Doc) Append(key string, val Val) Doc

Append adds an element to the end of the document, creating it from the key and value provided.

func (Doc) AppendMarshalBSON Uses

func (d Doc) AppendMarshalBSON(dst []byte) ([]byte, error)

AppendMarshalBSON marshals Doc to BSON bytes, appending to dst.

This method will never return an error.

func (Doc) Copy Uses

func (d Doc) Copy() Doc

Copy makes a shallow copy of this document.

func (Doc) Delete Uses

func (d Doc) Delete(key string) Doc

Delete removes the element with key if it exists and returns the updated Doc.

func (Doc) Equal Uses

func (d Doc) Equal(id IDoc) bool

Equal compares this document to another, returning true if they are equal.

func (Doc) IndexOf Uses

func (d Doc) IndexOf(key string) int

IndexOf returns the index of the first element with a key of key, or -1 if no element with a key was found.

func (Doc) Lookup Uses

func (d Doc) Lookup(key ...string) Val

Lookup searches the document and potentially subdocuments or arrays for the provided key. Each key provided to this method represents a layer of depth.

This method will return an empty Value if they key does not exist. To know if they key actually exists, use LookupErr.

func (Doc) LookupElement Uses

func (d Doc) LookupElement(key ...string) Elem

LookupElement searches the document and potentially subdocuments or arrays for the provided key. Each key provided to this method represents a layer of depth.

This method will return an empty Element if they key does not exist. To know if they key actually exists, use LookupElementErr.

func (Doc) LookupElementErr Uses

func (d Doc) LookupElementErr(key ...string) (Elem, error)

LookupElementErr searches the document and potentially subdocuments for the provided key. Each key provided to this method represents a layer of depth.

func (Doc) LookupErr Uses

func (d Doc) LookupErr(key ...string) (Val, error)

LookupErr searches the document and potentially subdocuments or arrays for the provided key. Each key provided to this method represents a layer of depth.

func (Doc) MarshalBSON Uses

func (d Doc) MarshalBSON() ([]byte, error)

MarshalBSON implements the Marshaler interface.

This method will never return an error.

func (Doc) MarshalBSONValue Uses

func (d Doc) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue implements the bsoncodec.ValueMarshaler interface.

This method will never return an error.

func (Doc) Prepend Uses

func (d Doc) Prepend(key string, val Val) Doc

Prepend adds an element to the beginning of the document, creating it from the key and value provided.

func (Doc) Set Uses

func (d Doc) Set(key string, val Val) Doc

Set replaces an element of a document. If an element with a matching key is found, the element will be replaced with the one provided. If the document does not have an element with that key, the element is appended to the document instead.

func (Doc) String Uses

func (d Doc) String() string

String implements the fmt.Stringer interface.

func (*Doc) UnmarshalBSON Uses

func (d *Doc) UnmarshalBSON(b []byte) error

UnmarshalBSON implements the Unmarshaler interface.

func (*Doc) UnmarshalBSONValue Uses

func (d *Doc) UnmarshalBSONValue(t bsontype.Type, data []byte) error

UnmarshalBSONValue implements the bson.ValueUnmarshaler interface.

type Elem Uses

type Elem struct {
    Key   string
    Value Val
}

Elem represents a BSON element.

NOTE: Element cannot be the value of a map nor a property of a struct without special handling. The default encoders and decoders will not process Element correctly. To do so would require information loss since an Element contains a key, but the keys used when encoding a struct are the struct field names. Instead of using an Element, use a Value as a value in a map or a property of a struct.

func (Elem) Equal Uses

func (e Elem) Equal(e2 Elem) bool

Equal compares e and e2 and returns true if they are equal.

func (Elem) String Uses

func (e Elem) String() string

type ElementTypeError Uses

type ElementTypeError struct {
    Method string
    Type   bsontype.Type
}

ElementTypeError specifies that a method to obtain a BSON value an incorrect type was called on a bson.Value.

TODO: rename this ValueTypeError.

func (ElementTypeError) Error Uses

func (ete ElementTypeError) Error() string

Error implements the error interface.

type IDoc Uses

type IDoc interface {
    // contains filtered or unexported methods
}

IDoc is the interface implemented by Doc and MDoc. It allows either of these types to be provided to the Document function to create a Value.

type KeyNotFound Uses

type KeyNotFound struct {
    Key   []string      // The keys that were searched for.
    Depth uint          // Which key either was not found or was an incorrect type.
    Type  bsontype.Type // The type of the key that was found but was an incorrect type.
}

KeyNotFound is an error type returned from the Lookup methods on Document. This type contains information about which key was not found and if it was actually not found or if a component of the key except the last was not a document nor array.

func (KeyNotFound) Error Uses

func (knf KeyNotFound) Error() string

type MDoc Uses

type MDoc map[string]Val

MDoc is an unordered, type safe, concise BSON document representation. This type should not be used if you require ordering of values or duplicate keys.

func ReadMDoc Uses

func ReadMDoc(b []byte) (MDoc, error)

ReadMDoc will create a Doc using the provided slice of bytes. If the slice of bytes is not a valid BSON document, this method will return an error.

func (MDoc) AppendMarshalBSON Uses

func (d MDoc) AppendMarshalBSON(dst []byte) ([]byte, error)

AppendMarshalBSON marshals Doc to BSON bytes, appending to dst.

This method will never return an error.

func (MDoc) Copy Uses

func (d MDoc) Copy() MDoc

Copy makes a shallow copy of this document.

func (MDoc) Equal Uses

func (d MDoc) Equal(id IDoc) bool

Equal compares this document to another, returning true if they are equal.

func (MDoc) Lookup Uses

func (d MDoc) Lookup(key ...string) Val

Lookup searches the document and potentially subdocuments or arrays for the provided key. Each key provided to this method represents a layer of depth.

This method will return an empty Value if they key does not exist. To know if they key actually exists, use LookupErr.

func (MDoc) LookupElement Uses

func (d MDoc) LookupElement(key ...string) Elem

LookupElement searches the document and potentially subdocuments or arrays for the provided key. Each key provided to this method represents a layer of depth.

This method will return an empty Element if they key does not exist. To know if they key actually exists, use LookupElementErr.

func (MDoc) LookupElementErr Uses

func (d MDoc) LookupElementErr(key ...string) (Elem, error)

LookupElementErr searches the document and potentially subdocuments for the provided key. Each key provided to this method represents a layer of depth.

func (MDoc) LookupErr Uses

func (d MDoc) LookupErr(key ...string) (Val, error)

LookupErr searches the document and potentially subdocuments or arrays for the provided key. Each key provided to this method represents a layer of depth.

func (MDoc) MarshalBSON Uses

func (d MDoc) MarshalBSON() ([]byte, error)

MarshalBSON implements the Marshaler interface.

This method will never return an error.

func (MDoc) MarshalBSONValue Uses

func (d MDoc) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue implements the bsoncodec.ValueMarshaler interface.

This method will never return an error.

func (MDoc) String Uses

func (d MDoc) String() string

String implements the fmt.Stringer interface.

func (*MDoc) UnmarshalBSON Uses

func (d *MDoc) UnmarshalBSON(b []byte) error

UnmarshalBSON implements the Unmarshaler interface.

type PrimitiveCodecs Uses

type PrimitiveCodecs struct{}

PrimitiveCodecs is a namespace for all of the default bsoncodec.Codecs for the primitive types defined in this package.

func (PrimitiveCodecs) ArrayDecodeValue Uses

func (pc PrimitiveCodecs) ArrayDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

ArrayDecodeValue is the ValueDecoderFunc for *Array.

func (PrimitiveCodecs) ArrayEncodeValue Uses

func (pc PrimitiveCodecs) ArrayEncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error

ArrayEncodeValue is the ValueEncoderFunc for *Array.

func (PrimitiveCodecs) DecodeDocument Uses

func (pc PrimitiveCodecs) DecodeDocument(dctx bsoncodec.DecodeContext, dr bsonrw.DocumentReader, pdoc *Doc) error

DecodeDocument haves decoding into a Doc from a bsonrw.DocumentReader.

func (PrimitiveCodecs) DocumentDecodeValue Uses

func (pc PrimitiveCodecs) DocumentDecodeValue(dctx bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

DocumentDecodeValue is the ValueDecoderFunc for *Document.

func (PrimitiveCodecs) DocumentEncodeValue Uses

func (pc PrimitiveCodecs) DocumentEncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error

DocumentEncodeValue is the ValueEncoderFunc for *Document.

func (PrimitiveCodecs) ElementSliceDecodeValue Uses

func (pc PrimitiveCodecs) ElementSliceDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

ElementSliceDecodeValue is the ValueDecoderFunc for []*Element.

func (PrimitiveCodecs) ElementSliceEncodeValue Uses

func (pc PrimitiveCodecs) ElementSliceEncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error

ElementSliceEncodeValue is the ValueEncoderFunc for []*Element.

func (PrimitiveCodecs) RegisterPrimitiveCodecs Uses

func (pc PrimitiveCodecs) RegisterPrimitiveCodecs(rb *bsoncodec.RegistryBuilder)

RegisterPrimitiveCodecs will register the encode and decode methods attached to PrimitiveCodecs with the provided RegistryBuilder. if rb is nil, a new empty RegistryBuilder will be created.

func (PrimitiveCodecs) ValueDecodeValue Uses

func (pc PrimitiveCodecs) ValueDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

ValueDecodeValue is the ValueDecoderFunc for *Value.

func (PrimitiveCodecs) ValueEncodeValue Uses

func (pc PrimitiveCodecs) ValueEncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error

ValueEncodeValue is the ValueEncoderFunc for *Value.

type Val Uses

type Val struct {
    // contains filtered or unexported fields
}

Val represents a BSON value.

func Array Uses

func Array(arr Arr) Val

Array constructs a Value from arr. If arr is nil, a BSON Null value is returned.

Code:

internalVersion := "1234567"

f := func(appName string) Arr {
    arr := make(Arr, 0)
    arr = append(arr,
        Document(Doc{{"name", String("mongo-go-driver")}, {"version", String(internalVersion)}}),
        Document(Doc{{"type", String("darwin")}, {"architecture", String("amd64")}}),
        String("go1.9.2"),
    )
    if appName != "" {
        arr = append(arr, Document(MDoc{"name": String(appName)}))
    }

    return arr
}
_, buf, err := f("hello-world").MarshalBSONValue()
if err != nil {
    fmt.Println(err)
}
fmt.Println(buf)

Output:

[154 0 0 0 3 48 0 52 0 0 0 2 110 97 109 101 0 16 0 0 0 109 111 110 103 111 45 103 111 45 100 114 105 118 101 114 0 2 118 101 114 115 105 111 110 0 8 0 0 0 49 50 51 52 53 54 55 0 0 3 49 0 46 0 0 0 2 116 121 112 101 0 7 0 0 0 100 97 114 119 105 110 0 2 97 114 99 104 105 116 101 99 116 117 114 101 0 6 0 0 0 97 109 100 54 52 0 0 2 50 0 8 0 0 0 103 111 49 46 57 46 50 0 3 51 0 27 0 0 0 2 110 97 109 101 0 12 0 0 0 104 101 108 108 111 45 119 111 114 108 100 0 0 0]

func Binary Uses

func Binary(subtype byte, data []byte) Val

Binary constructs a BSON binary Value.

func Boolean Uses

func Boolean(b bool) Val

Boolean constructs a BSON boolean Value.

func CodeWithScope Uses

func CodeWithScope(code string, scope IDoc) Val

CodeWithScope constructs a BSON code with scope Value.

func DBPointer Uses

func DBPointer(ns string, ptr primitive.ObjectID) Val

DBPointer constructs a BSON dbpointer Value.

func DateTime Uses

func DateTime(dt int64) Val

DateTime constructs a BSON datetime Value.

func Decimal128 Uses

func Decimal128(d128 primitive.Decimal128) Val

Decimal128 constructs a BSON decimal128 Value.

func Document Uses

func Document(doc IDoc) Val

Document constructs a Value from the given IDoc. If nil is provided, a BSON Null value will be returned.

Code:

internalVersion := "1234567"

f := func(appName string) Doc {
    doc := Doc{
        {"driver", Document(Doc{{"name", String("mongo-go-driver")}, {"version", String(internalVersion)}})},
        {"os", Document(Doc{{"type", String("darwin")}, {"architecture", String("amd64")}})},
        {"platform", String("go1.11.1")},
    }
    if appName != "" {
        doc = append(doc, Elem{"application", Document(MDoc{"name": String(appName)})})
    }

    return doc
}
buf, err := f("hello-world").MarshalBSON()
if err != nil {
    fmt.Println(err)
}
fmt.Println(buf)

Output:

[178 0 0 0 3 100 114 105 118 101 114 0 52 0 0 0 2 110 97 109 101 0 16 0 0 0 109 111 110 103 111 45 103 111 45 100 114 105 118 101 114 0 2 118 101 114 115 105 111 110 0 8 0 0 0 49 50 51 52 53 54 55 0 0 3 111 115 0 46 0 0 0 2 116 121 112 101 0 7 0 0 0 100 97 114 119 105 110 0 2 97 114 99 104 105 116 101 99 116 117 114 101 0 6 0 0 0 97 109 100 54 52 0 0 2 112 108 97 116 102 111 114 109 0 9 0 0 0 103 111 49 46 49 49 46 49 0 3 97 112 112 108 105 99 97 116 105 111 110 0 27 0 0 0 2 110 97 109 101 0 12 0 0 0 104 101 108 108 111 45 119 111 114 108 100 0 0 0]

func Double Uses

func Double(f64 float64) Val

Double constructs a BSON double Value.

func Int32 Uses

func Int32(i32 int32) Val

Int32 constructs a BSON int32 Value.

func Int64 Uses

func Int64(i64 int64) Val

Int64 constructs a BSON int64 Value.

func JavaScript Uses

func JavaScript(js string) Val

JavaScript constructs a BSON javascript Value.

func MaxKey Uses

func MaxKey() Val

MaxKey constructs a BSON maxkey Value.

func MinKey Uses

func MinKey() Val

MinKey constructs a BSON minkey Value.

func Null Uses

func Null() Val

Null constructs a BSON binary Value.

func ObjectID Uses

func ObjectID(oid primitive.ObjectID) Val

ObjectID constructs a BSON objectid Value.

func Regex Uses

func Regex(pattern, options string) Val

Regex constructs a BSON regex Value.

func String Uses

func String(str string) Val

String constructs a BSON string Value.

func Symbol Uses

func Symbol(symbol string) Val

Symbol constructs a BSON symbol Value.

func Time Uses

func Time(t time.Time) Val

Time constructs a BSON datetime Value.

func Timestamp Uses

func Timestamp(t, i uint32) Val

Timestamp constructs a BSON timestamp Value.

func Undefined Uses

func Undefined() Val

Undefined constructs a BSON binary Value.

func (Val) Array Uses

func (v Val) Array() Arr

Array returns the BSON array value the Value represents. It panics if the value is a BSON type other than array.

func (Val) ArrayOK Uses

func (v Val) ArrayOK() (Arr, bool)

ArrayOK is the same as Array, except it returns a boolean instead of panicking.

func (Val) Binary Uses

func (v Val) Binary() (byte, []byte)

Binary returns the BSON binary value the Value represents. It panics if the value is a BSON type other than binary.

func (Val) BinaryOK Uses

func (v Val) BinaryOK() (byte, []byte, bool)

BinaryOK is the same as Binary, except it returns a boolean instead of panicking.

func (Val) Boolean Uses

func (v Val) Boolean() bool

Boolean returns the BSON boolean the Value represents. It panics if the value is a BSON type other than boolean.

func (Val) BooleanOK Uses

func (v Val) BooleanOK() (bool, bool)

BooleanOK is the same as Boolean, except it returns a boolean instead of panicking.

func (Val) CodeWithScope Uses

func (v Val) CodeWithScope() (string, Doc)

CodeWithScope returns the BSON code with scope value the Value represents. It panics if the value is a BSON type other than code with scope.

func (Val) CodeWithScopeOK Uses

func (v Val) CodeWithScopeOK() (string, Doc, bool)

CodeWithScopeOK is the same as JavascriptWithScope, except that it returns a boolean instead of panicking.

func (Val) DBPointer Uses

func (v Val) DBPointer() (string, primitive.ObjectID)

DBPointer returns the BSON dbpointer the Value represents. It panics if the value is a BSON type other than dbpointer.

func (Val) DBPointerOK Uses

func (v Val) DBPointerOK() (string, primitive.ObjectID, bool)

DBPointerOK is the same as DBPoitner, except that it returns a boolean instead of panicking.

func (Val) DateTime Uses

func (v Val) DateTime() int64

DateTime returns the BSON datetime the Value represents. It panics if the value is a BSON type other than datetime.

func (Val) DateTimeOK Uses

func (v Val) DateTimeOK() (int64, bool)

DateTimeOK is the same as DateTime, except it returns a boolean instead of panicking.

func (Val) Decimal128 Uses

func (v Val) Decimal128() primitive.Decimal128

Decimal128 returns the BSON decimal128 value the Value represents. It panics if the value is a BSON type other than decimal128.

func (Val) Decimal128OK Uses

func (v Val) Decimal128OK() (primitive.Decimal128, bool)

Decimal128OK is the same as Decimal128, except that it returns a boolean instead of panicking.

func (Val) Document Uses

func (v Val) Document() Doc

Document returns the BSON embedded document value the Value represents. It panics if the value is a BSON type other than embedded document.

func (Val) DocumentOK Uses

func (v Val) DocumentOK() (Doc, bool)

DocumentOK is the same as Document, except it returns a boolean instead of panicking.

func (Val) Double Uses

func (v Val) Double() float64

Double returns the BSON double value the Value represents. It panics if the value is a BSON type other than double.

func (Val) DoubleOK Uses

func (v Val) DoubleOK() (float64, bool)

DoubleOK is the same as Double, but returns a boolean instead of panicking.

func (Val) Equal Uses

func (v Val) Equal(v2 Val) bool

Equal compares v to v2 and returns true if they are equal. Unknown BSON types are never equal. Two empty values are equal.

func (Val) Int32 Uses

func (v Val) Int32() int32

Int32 returns the BSON int32 the Value represents. It panics if the value is a BSON type other than int32.

func (Val) Int32OK Uses

func (v Val) Int32OK() (int32, bool)

Int32OK is the same as Int32, except that it returns a boolean instead of panicking.

func (Val) Int64 Uses

func (v Val) Int64() int64

Int64 returns the BSON int64 the Value represents. It panics if the value is a BSON type other than int64.

func (Val) Int64OK Uses

func (v Val) Int64OK() (int64, bool)

Int64OK is the same as Int64, except that it returns a boolean instead of panicking.

func (Val) Interface Uses

func (v Val) Interface() interface{}

Interface returns the Go value of this Value as an empty interface.

This method will return nil if it is empty, otherwise it will return a Go primitive or a primitive.* instance.

func (Val) IsNumber Uses

func (v Val) IsNumber() bool

IsNumber returns true if the type of v is a numberic BSON type.

func (Val) IsZero Uses

func (v Val) IsZero() bool

IsZero returns true if this value is zero or a BSON null.

func (Val) JavaScript Uses

func (v Val) JavaScript() string

JavaScript returns the BSON JavaScript the Value represents. It panics if the value is a BSON type other than JavaScript.

func (Val) JavaScriptOK Uses

func (v Val) JavaScriptOK() (string, bool)

JavaScriptOK is the same as Javascript, except that it returns a boolean instead of panicking.

func (Val) MDocument Uses

func (v Val) MDocument() MDoc

MDocument returns the BSON embedded document value the Value represents. It panics if the value is a BSON type other than embedded document.

func (Val) MDocumentOK Uses

func (v Val) MDocumentOK() (MDoc, bool)

MDocumentOK is the same as Document, except it returns a boolean instead of panicking.

func (Val) MarshalAppendBSONValue Uses

func (v Val) MarshalAppendBSONValue(dst []byte) (bsontype.Type, []byte, error)

MarshalAppendBSONValue is similar to MarshalBSONValue, but allows the caller to specify a slice to add the bytes to.

func (Val) MarshalBSONValue Uses

func (v Val) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue implements the bsoncodec.ValueMarshaler interface.

func (Val) MaxKey Uses

func (v Val) MaxKey()

MaxKey returns the BSON maxkey the Value represents. It panics if the value is a BSON type other than binary.

func (Val) MaxKeyOK Uses

func (v Val) MaxKeyOK() bool

MaxKeyOK is the same as MaxKey, except it returns a boolean instead of panicking.

func (Val) MinKey Uses

func (v Val) MinKey()

MinKey returns the BSON minkey the Value represents. It panics if the value is a BSON type other than binary.

func (Val) MinKeyOK Uses

func (v Val) MinKeyOK() bool

MinKeyOK is the same as MinKey, except it returns a boolean instead of panicking.

func (Val) Null Uses

func (v Val) Null()

Null returns the BSON undefined the Value represents. It panics if the value is a BSON type other than binary.

func (Val) NullOK Uses

func (v Val) NullOK() bool

NullOK is the same as Null, except it returns a boolean instead of panicking.

func (Val) ObjectID Uses

func (v Val) ObjectID() primitive.ObjectID

ObjectID returns the BSON ObjectID the Value represents. It panics if the value is a BSON type other than ObjectID.

func (Val) ObjectIDOK Uses

func (v Val) ObjectIDOK() (primitive.ObjectID, bool)

ObjectIDOK is the same as ObjectID, except it returns a boolean instead of panicking.

func (Val) Regex Uses

func (v Val) Regex() (pattern, options string)

Regex returns the BSON regex the Value represents. It panics if the value is a BSON type other than regex.

func (Val) RegexOK Uses

func (v Val) RegexOK() (pattern, options string, ok bool)

RegexOK is the same as Regex, except that it returns a boolean instead of panicking.

func (Val) String Uses

func (v Val) String() string

func (Val) StringValue Uses

func (v Val) StringValue() string

StringValue returns the BSON string the Value represents. It panics if the value is a BSON type other than string.

NOTE: This method is called StringValue to avoid it implementing the fmt.Stringer interface.

func (Val) StringValueOK Uses

func (v Val) StringValueOK() (string, bool)

StringValueOK is the same as StringValue, but returns a boolean instead of panicking.

func (Val) Symbol Uses

func (v Val) Symbol() string

Symbol returns the BSON symbol the Value represents. It panics if the value is a BSON type other than symbol.

func (Val) SymbolOK Uses

func (v Val) SymbolOK() (string, bool)

SymbolOK is the same as Javascript, except that it returns a boolean instead of panicking.

func (Val) Time Uses

func (v Val) Time() time.Time

Time returns the BSON datetime the Value represents as time.Time. It panics if the value is a BSON type other than datetime.

func (Val) TimeOK Uses

func (v Val) TimeOK() (time.Time, bool)

TimeOK is the same as Time, except it returns a boolean instead of panicking.

func (Val) Timestamp Uses

func (v Val) Timestamp() (t, i uint32)

Timestamp returns the BSON timestamp the Value represents. It panics if the value is a BSON type other than timestamp.

func (Val) TimestampOK Uses

func (v Val) TimestampOK() (t uint32, i uint32, ok bool)

TimestampOK is the same as Timestamp, except that it returns a boolean instead of panicking.

func (Val) Type Uses

func (v Val) Type() bsontype.Type

Type returns the BSON type of this value.

func (Val) Undefined Uses

func (v Val) Undefined()

Undefined returns the BSON undefined the Value represents. It panics if the value is a BSON type other than binary.

func (Val) UndefinedOK Uses

func (v Val) UndefinedOK() bool

UndefinedOK is the same as Undefined, except it returns a boolean instead of panicking.

func (*Val) UnmarshalBSONValue Uses

func (v *Val) UnmarshalBSONValue(t bsontype.Type, data []byte) error

UnmarshalBSONValue implements the bsoncodec.ValueUnmarshaler interface.

Directories

PathSynopsis
bsoncorePackage bsoncore contains functions that can be used to encode and decode BSON elements and values to or from a slice of bytes.

Package bsonx imports 14 packages (graph) and is imported by 27 packages. Updated 2019-07-12. Refresh now. Tools for package owners.