mongo-go-driver: github.com/mongodb/mongo-go-driver/bson Index | Examples | Files | Directories

package bson

import "github.com/mongodb/mongo-go-driver/bson"

Package bson is a library for reading, writing, and manipulating BSON. The library has two families of types for representing BSON.

The Raw family of types is used to validate and retrieve elements from a slice of bytes. This type is most useful when you want do lookups on BSON bytes without unmarshaling it into another type.

Example:

var raw bson.Raw = ... // bytes from somewhere
err := raw.Validate()
if err != nil { return err }
val := raw.Lookup("foo")
i32, ok := val.Int32OK()
// do something with i32...

The D family of types is used to build concise representations of BSON using native Go types. These types do not support automatic lookup.

Example:

bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}}

Marshaling and Unmarshaling are handled with the Marshal and Unmarshal family of functions. If you need to write or read BSON from a non-slice source, an Encoder or Decoder can be used with a bsonrw.ValueWriter or bsonrw.ValueReader.

Example:

b, err := bson.Marshal(bson.D{{"foo", "bar"}})
if err != nil { return err }
var fooer struct {
	Foo string
}
err = bson.Unmarshal(b, &fooer)
if err != nil { return err }
// do something with fooer...

Index

Examples

Package Files

bson.go decoder.go doc.go encoder.go marshal.go primitive_codecs.go raw.go raw_element.go raw_value.go registry.go types.go unmarshal.go

Constants

const (
    TypeDouble           = bsontype.Double
    TypeString           = bsontype.String
    TypeEmbeddedDocument = bsontype.EmbeddedDocument
    TypeArray            = bsontype.Array
    TypeBinary           = bsontype.Binary
    TypeUndefined        = bsontype.Undefined
    TypeObjectID         = bsontype.ObjectID
    TypeBoolean          = bsontype.Boolean
    TypeDateTime         = bsontype.DateTime
    TypeNull             = bsontype.Null
    TypeRegex            = bsontype.Regex
    TypeDBPointer        = bsontype.DBPointer
    TypeJavaScript       = bsontype.JavaScript
    TypeSymbol           = bsontype.Symbol
    TypeCodeWithScope    = bsontype.CodeWithScope
    TypeInt32            = bsontype.Int32
    TypeTimestamp        = bsontype.Timestamp
    TypeInt64            = bsontype.Int64
    TypeDecimal128       = bsontype.Decimal128
    TypeMinKey           = bsontype.MinKey
    TypeMaxKey           = bsontype.MaxKey
)

These constants uniquely refer to each BSON type.

Variables

var DefaultRegistry = NewRegistryBuilder().Build()

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

var ErrNilContext = errors.New("DecodeContext cannot be nil")

ErrNilContext is returned when the provided DecodeContext is nil.

var ErrNilReader = errors.New("nil reader")

ErrNilReader indicates that an operation was attempted on a nil bson.Reader.

var ErrNilRegistry = errors.New("Registry cannot be nil")

ErrNilRegistry is returned when the provided registry is nil.

func Marshal Uses

func Marshal(val interface{}) ([]byte, error)

Marshal returns the BSON encoding of val.

Marshal will use the default registry created by NewRegistry to recursively marshal val into a []byte. Marshal will inspect struct tags and alter the marshaling process accordingly.

func MarshalAppend Uses

func MarshalAppend(dst []byte, val interface{}) ([]byte, error)

MarshalAppend will append the BSON encoding of val to dst. If dst is not large enough to hold the BSON encoding of val, dst will be grown.

func MarshalAppendWithContext Uses

func MarshalAppendWithContext(ec bsoncodec.EncodeContext, dst []byte, val interface{}) ([]byte, error)

MarshalAppendWithContext will append the BSON encoding of val to dst using EncodeContext ec. If dst is not large enough to hold the BSON encoding of val, dst will be grown.

func MarshalAppendWithRegistry Uses

func MarshalAppendWithRegistry(r *bsoncodec.Registry, dst []byte, val interface{}) ([]byte, error)

MarshalAppendWithRegistry will append the BSON encoding of val to dst using Registry r. If dst is not large enough to hold the BSON encoding of val, dst will be grown.

func MarshalExtJSON Uses

func MarshalExtJSON(val interface{}, canonical, escapeHTML bool) ([]byte, error)

MarshalExtJSON returns the extended JSON encoding of val.

func MarshalExtJSONAppend Uses

func MarshalExtJSONAppend(dst []byte, val interface{}, canonical, escapeHTML bool) ([]byte, error)

MarshalExtJSONAppend will append the extended JSON encoding of val to dst. If dst is not large enough to hold the extended JSON encoding of val, dst will be grown.

func MarshalExtJSONAppendWithContext Uses

func MarshalExtJSONAppendWithContext(ec bsoncodec.EncodeContext, dst []byte, val interface{}, canonical, escapeHTML bool) ([]byte, error)

MarshalExtJSONAppendWithContext will append the extended JSON encoding of val to dst using Registry r. If dst is not large enough to hold the BSON encoding of val, dst will be grown.

func MarshalExtJSONAppendWithRegistry Uses

func MarshalExtJSONAppendWithRegistry(r *bsoncodec.Registry, dst []byte, val interface{}, canonical, escapeHTML bool) ([]byte, error)

MarshalExtJSONAppendWithRegistry will append the extended JSON encoding of val to dst using Registry r. If dst is not large enough to hold the BSON encoding of val, dst will be grown.

func MarshalExtJSONWithContext Uses

func MarshalExtJSONWithContext(ec bsoncodec.EncodeContext, val interface{}, canonical, escapeHTML bool) ([]byte, error)

MarshalExtJSONWithContext returns the extended JSON encoding of val using Registry r.

func MarshalExtJSONWithRegistry Uses

func MarshalExtJSONWithRegistry(r *bsoncodec.Registry, val interface{}, canonical, escapeHTML bool) ([]byte, error)

MarshalExtJSONWithRegistry returns the extended JSON encoding of val using Registry r.

func MarshalWithContext Uses

func MarshalWithContext(ec bsoncodec.EncodeContext, val interface{}) ([]byte, error)

MarshalWithContext returns the BSON encoding of val using EncodeContext ec.

func MarshalWithRegistry Uses

func MarshalWithRegistry(r *bsoncodec.Registry, val interface{}) ([]byte, error)

MarshalWithRegistry returns the BSON encoding of val using Registry r.

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.

func Unmarshal Uses

func Unmarshal(data []byte, val interface{}) error

Unmarshal parses the BSON-encoded data and stores the result in the value pointed to by val. If val is nil or not a pointer, Unmarshal returns InvalidUnmarshalError.

func UnmarshalExtJSON Uses

func UnmarshalExtJSON(data []byte, canonical bool, val interface{}) error

UnmarshalExtJSON parses the extended JSON-encoded data and stores the result in the value pointed to by val. If val is nil or not a pointer, Unmarshal returns InvalidUnmarshalError.

func UnmarshalExtJSONWithContext Uses

func UnmarshalExtJSONWithContext(dc bsoncodec.DecodeContext, data []byte, canonical bool, val interface{}) error

UnmarshalExtJSONWithContext parses the extended JSON-encoded data using DecodeContext dc and stores the result in the value pointed to by val. If val is nil or not a pointer, UnmarshalWithRegistry returns InvalidUnmarshalError.

func UnmarshalExtJSONWithRegistry Uses

func UnmarshalExtJSONWithRegistry(r *bsoncodec.Registry, data []byte, canonical bool, val interface{}) error

UnmarshalExtJSONWithRegistry parses the extended JSON-encoded data using Registry r and stores the result in the value pointed to by val. If val is nil or not a pointer, UnmarshalWithRegistry returns InvalidUnmarshalError.

func UnmarshalWithContext Uses

func UnmarshalWithContext(dc bsoncodec.DecodeContext, data []byte, val interface{}) error

UnmarshalWithContext parses the BSON-encoded data using DecodeContext dc and stores the result in the value pointed to by val. If val is nil or not a pointer, UnmarshalWithRegistry returns InvalidUnmarshalError.

func UnmarshalWithRegistry Uses

func UnmarshalWithRegistry(r *bsoncodec.Registry, data []byte, val interface{}) error

UnmarshalWithRegistry parses the BSON-encoded data using Registry r and stores the result in the value pointed to by val. If val is nil or not a pointer, UnmarshalWithRegistry returns InvalidUnmarshalError.

type A Uses

type A = primitive.A

An A represents a BSON array. This type can be used to represent a BSON array in a concise and readable manner. It should generally be used when serializing to BSON. For deserializing, the RawArray or Array types should be used.

Example usage:

bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}}

type D Uses

type D = primitive.D

D represents a BSON Document. This type can be used to represent BSON in a concise and readable manner. It should generally be used when serializing to BSON. For deserializing, the Raw or Document types should be used.

Example usage:

bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}}

This type should be used in situations where order matters, such as MongoDB commands. If the order is not important, a map is more comfortable and concise.

type Decoder Uses

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

A Decoder reads and decodes BSON documents from a stream. It reads from a bsonrw.ValueReader as the source of BSON data.

func NewDecoder Uses

func NewDecoder(vr bsonrw.ValueReader) (*Decoder, error)

NewDecoder returns a new decoder that uses the DefaultRegistry to read from vr.

func NewDecoderWithContext Uses

func NewDecoderWithContext(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader) (*Decoder, error)

NewDecoderWithContext returns a new decoder that uses DecodeContext dc to read from vr.

func (*Decoder) Decode Uses

func (d *Decoder) Decode(val interface{}) error

Decode reads the next BSON document from the stream and decodes it into the value pointed to by val.

The documentation for Unmarshal contains details about of BSON into a Go value.

func (*Decoder) Reset Uses

func (d *Decoder) Reset(vr bsonrw.ValueReader) error

Reset will reset the state of the decoder, using the same *DecodeContext used in the original construction but using vr for reading.

func (*Decoder) SetContext Uses

func (d *Decoder) SetContext(dc bsoncodec.DecodeContext) error

SetContext replaces the current registry of the decoder with dc.

func (*Decoder) SetRegistry Uses

func (d *Decoder) SetRegistry(r *bsoncodec.Registry) error

SetRegistry replaces the current registry of the decoder with r.

type E Uses

type E = primitive.E

E represents a BSON element for a D. It is usually used inside a D.

type Encoder Uses

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

An Encoder writes a serialization format to an output stream. It writes to a bsonrw.ValueWriter as the destination of BSON data.

func NewEncoder Uses

func NewEncoder(vw bsonrw.ValueWriter) (*Encoder, error)

NewEncoder returns a new encoder that uses the DefaultRegistry to write to vw.

func NewEncoderWithContext Uses

func NewEncoderWithContext(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter) (*Encoder, error)

NewEncoderWithContext returns a new encoder that uses EncodeContext ec to write to vw.

func (*Encoder) Encode Uses

func (e *Encoder) Encode(val interface{}) error

Encode writes the BSON encoding of val to the stream.

The documentation for Marshal contains details about the conversion of Go values to BSON.

func (*Encoder) Reset Uses

func (e *Encoder) Reset(vw bsonrw.ValueWriter) error

Reset will reset the state of the encoder, using the same *EncodeContext used in the original construction but using vw.

func (*Encoder) SetContext Uses

func (e *Encoder) SetContext(ec bsoncodec.EncodeContext) error

SetContext replaces the current EncodeContext of the encoder with er.

func (*Encoder) SetRegistry Uses

func (e *Encoder) SetRegistry(r *bsoncodec.Registry) error

SetRegistry replaces the current registry of the encoder with r.

type M Uses

type M = primitive.M

M is an unordered, concise representation of a BSON Document. It should generally be used to serialize BSON when the order of the elements of a BSON document do not matter. If the element order matters, use a D instead.

Example usage:

bson.M{"foo": "bar", "hello": "world", "pi": 3.14159}

This type is handled in the encoders as a regular map[string]interface{}. The elements will be serialized in an undefined, random order, and the order will be different each time.

type Marshaler Uses

type Marshaler interface {
    MarshalBSON() ([]byte, error)
}

Marshaler is an interface implemented by types that can marshal themselves into a BSON document represented as bytes. The bytes returned must be a valid BSON document if the error is nil.

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) RawDecodeValue Uses

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

RawDecodeValue is the ValueDecoderFunc for Reader.

func (PrimitiveCodecs) RawEncodeValue Uses

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

RawEncodeValue is the ValueEncoderFunc for Reader.

func (PrimitiveCodecs) RawValueDecodeValue Uses

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

RawValueDecodeValue is the ValueDecoderFunc for RawValue.

func (PrimitiveCodecs) RawValueEncodeValue Uses

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

RawValueEncodeValue is the ValueEncoderFunc for RawValue.

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.

type Raw Uses

type Raw []byte

Raw is a wrapper around a byte slice. It will interpret the slice as a BSON document. This type is a wrapper around a bsoncore.Document. Errors returned from the methods on this type and associated types come from the bsoncore package.

func NewFromIOReader Uses

func NewFromIOReader(r io.Reader) (Raw, error)

NewFromIOReader reads in a document from the given io.Reader and constructs a Raw from it.

func (Raw) Elements Uses

func (r Raw) Elements() ([]RawElement, error)

Elements returns this document as a slice of elements. The returned slice will contain valid elements. If the document is not valid, the elements up to the invalid point will be returned along with an error.

func (Raw) Index Uses

func (r Raw) Index(index uint) RawElement

Index searches for and retrieves the element at the given index. This method will panic if the document is invalid or if the index is out of bounds.

func (Raw) IndexErr Uses

func (r Raw) IndexErr(index uint) (RawElement, error)

IndexErr searches for and retrieves the element at the given index.

func (Raw) Lookup Uses

func (r Raw) Lookup(key ...string) RawValue

Lookup search the document, potentially recursively, for the given key. If there are multiple keys provided, this method will recurse down, as long as the top and intermediate nodes are either documents or arrays.If an error occurs or if the value doesn't exist, an empty RawValue is returned.

func (Raw) LookupErr Uses

func (r Raw) LookupErr(key ...string) (RawValue, 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 (Raw) String Uses

func (r Raw) String() string

String implements the fmt.Stringer interface.

func (Raw) Validate Uses

func (r Raw) Validate() (err error)

Validate validates the document. This method only validates the first document in the slice, to validate other documents, the slice must be resliced.

Code:

rdr := make(Raw, 500)
rdr[250], rdr[251], rdr[252], rdr[253], rdr[254] = '\x05', '\x00', '\x00', '\x00', '\x00'
err := rdr[250:].Validate()
fmt.Println(err)

Output:

<nil>

func (Raw) Values Uses

func (r Raw) Values() ([]RawValue, error)

Values returns this document as a slice of values. The returned slice will contain valid values. If the document is not valid, the values up to the invalid point will be returned along with an error.

type RawElement Uses

type RawElement []byte

RawElement represents a BSON element in byte form. This type provides a simple way to transform a slice of bytes into a BSON element and extract information from it.

RawElement is a thin wrapper around a bsoncore.Element.

func (RawElement) DebugString Uses

func (re RawElement) DebugString() string

DebugString outputs a human readable version of RawElement. It will attempt to stringify the valid components of the element even if the entire element is not valid.

func (RawElement) Key Uses

func (re RawElement) Key() string

Key returns the key for this element. If the element is not valid, this method returns an empty string. If knowing if the element is valid is important, use KeyErr.

func (RawElement) KeyErr Uses

func (re RawElement) KeyErr() (string, error)

KeyErr returns the key for this element, returning an error if the element is not valid.

func (RawElement) String Uses

func (re RawElement) String() string

String implements the fmt.Stringer interface. The output will be in extended JSON format.

func (RawElement) Validate Uses

func (re RawElement) Validate() error

Validate ensures re is a valid BSON element.

func (RawElement) Value Uses

func (re RawElement) Value() RawValue

Value returns the value of this element. If the element is not valid, this method returns an empty Value. If knowing if the element is valid is important, use ValueErr.

func (RawElement) ValueErr Uses

func (re RawElement) ValueErr() (RawValue, error)

ValueErr returns the value for this element, returning an error if the element is not valid.

type RawValue Uses

type RawValue struct {
    Type  bsontype.Type
    Value []byte
    // contains filtered or unexported fields
}

RawValue represents a BSON value in byte form. It can be used to hold unprocessed BSON or to defer processing of BSON. Type is the BSON type of the value and Value are the raw bytes that represent the element.

This type wraps bsoncore.Value for most of it's functionality.

func (RawValue) Array Uses

func (rv RawValue) Array() Raw

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

func (RawValue) ArrayOK Uses

func (rv RawValue) ArrayOK() (Raw, bool)

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

func (RawValue) Binary Uses

func (rv RawValue) Binary() (subtype byte, data []byte)

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

func (RawValue) BinaryOK Uses

func (rv RawValue) BinaryOK() (subtype byte, data []byte, ok bool)

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

func (RawValue) Boolean Uses

func (rv RawValue) Boolean() bool

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

func (RawValue) BooleanOK Uses

func (rv RawValue) BooleanOK() (bool, bool)

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

func (RawValue) CodeWithScope Uses

func (rv RawValue) CodeWithScope() (string, Raw)

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

func (RawValue) CodeWithScopeOK Uses

func (rv RawValue) CodeWithScopeOK() (string, Raw, bool)

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

func (RawValue) DBPointer Uses

func (rv RawValue) DBPointer() (string, primitive.ObjectID)

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

func (RawValue) DBPointerOK Uses

func (rv RawValue) DBPointerOK() (string, primitive.ObjectID, bool)

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

func (RawValue) DateTime Uses

func (rv RawValue) DateTime() int64

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

func (RawValue) DateTimeOK Uses

func (rv RawValue) DateTimeOK() (int64, bool)

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

func (RawValue) DebugString Uses

func (rv RawValue) DebugString() string

DebugString outputs a human readable version of Document. It will attempt to stringify the valid components of the document even if the entire document is not valid.

func (RawValue) Decimal128 Uses

func (rv RawValue) Decimal128() primitive.Decimal128

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

func (RawValue) Decimal128OK Uses

func (rv RawValue) Decimal128OK() (primitive.Decimal128, bool)

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

func (RawValue) Document Uses

func (rv RawValue) Document() Raw

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

func (RawValue) DocumentOK Uses

func (rv RawValue) DocumentOK() (Raw, bool)

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

func (RawValue) Double Uses

func (rv RawValue) Double() float64

Double returns the float64 value for this element. It panics if e's BSON type is not bsontype.Double.

func (RawValue) DoubleOK Uses

func (rv RawValue) DoubleOK() (float64, bool)

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

func (RawValue) Equal Uses

func (rv RawValue) Equal(rv2 RawValue) bool

Equal compares rv and rv2 and returns true if they are equal.

func (RawValue) Int32 Uses

func (rv RawValue) Int32() int32

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

func (RawValue) Int32OK Uses

func (rv RawValue) Int32OK() (int32, bool)

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

func (RawValue) Int64 Uses

func (rv RawValue) Int64() int64

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

func (RawValue) Int64OK Uses

func (rv RawValue) Int64OK() (int64, bool)

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

func (RawValue) IsNumber Uses

func (rv RawValue) IsNumber() bool

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

func (RawValue) JavaScript Uses

func (rv RawValue) JavaScript() string

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

func (RawValue) JavaScriptOK Uses

func (rv RawValue) JavaScriptOK() (string, bool)

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

func (RawValue) ObjectID Uses

func (rv RawValue) ObjectID() primitive.ObjectID

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

func (RawValue) ObjectIDOK Uses

func (rv RawValue) ObjectIDOK() (primitive.ObjectID, bool)

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

func (RawValue) Regex Uses

func (rv RawValue) Regex() (pattern, options string)

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

func (RawValue) RegexOK Uses

func (rv RawValue) RegexOK() (pattern, options string, ok bool)

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

func (RawValue) String Uses

func (rv RawValue) String() string

String implements the fmt.String interface. This method will return values in extended JSON format. If the value is not valid, this returns an empty string

func (RawValue) StringValue Uses

func (rv RawValue) StringValue() string

StringValue returns the string value for this element. It panics if e's BSON type is not bsontype.String.

NOTE: This method is called StringValue to avoid a collision with the String method which implements the fmt.Stringer interface.

func (RawValue) StringValueOK Uses

func (rv RawValue) StringValueOK() (string, bool)

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

func (RawValue) Symbol Uses

func (rv RawValue) Symbol() string

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

func (RawValue) SymbolOK Uses

func (rv RawValue) SymbolOK() (string, bool)

SymbolOK is the same as Symbol, excepti that it returns a boolean instead of panicking.

func (RawValue) Time Uses

func (rv RawValue) Time() time.Time

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

func (RawValue) TimeOK Uses

func (rv RawValue) TimeOK() (time.Time, bool)

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

func (RawValue) Timestamp Uses

func (rv RawValue) Timestamp() (t, i uint32)

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

func (RawValue) TimestampOK Uses

func (rv RawValue) TimestampOK() (t, i uint32, ok bool)

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

func (RawValue) Unmarshal Uses

func (rv RawValue) Unmarshal(val interface{}) error

Unmarshal deserializes BSON into the provided val. If RawValue cannot be unmarshaled into val, an error is returned. This method will use the registry used to create the RawValue, if the RawValue was created from partial BSON processing, or it will use the default registry. Users wishing to specify the registry to use should use UnmarshalWithRegistry.

func (RawValue) UnmarshalWithContext Uses

func (rv RawValue) UnmarshalWithContext(dc *bsoncodec.DecodeContext, val interface{}) error

UnmarshalWithContext performs the same unmarshalling as Unmarshal but uses the provided DecodeContext instead of the one attached or the default registry.

func (RawValue) UnmarshalWithRegistry Uses

func (rv RawValue) UnmarshalWithRegistry(r *bsoncodec.Registry, val interface{}) error

UnmarshalWithRegistry performs the same unmarshalling as Unmarshal but uses the provided registry instead of the one attached or the default registry.

func (RawValue) Validate Uses

func (rv RawValue) Validate() error

Validate ensures the value is a valid BSON value.

type Unmarshaler Uses

type Unmarshaler interface {
    UnmarshalBSON([]byte) error
}

Unmarshaler is an interface implemented by types that can unmarshal a BSON document representation of themselves. The BSON bytes can be assumed to be valid. UnmarshalBSON must copy the BSON bytes if it wishes to retain the data after returning.

type ValueMarshaler Uses

type ValueMarshaler interface {
    MarshalBSONValue() (bsontype.Type, []byte, error)
}

ValueMarshaler is an interface implemented by types that can marshal themselves into a BSON value as bytes. The type must be the valid type for the bytes returned. The bytes and byte type together must be valid if the error is nil.

type ValueUnmarshaler Uses

type ValueUnmarshaler interface {
    UnmarshalBSONValue(bsontype.Type, []byte) error
}

ValueUnmarshaler is an interface implemented by types that can unmarshal a BSON value representaiton of themselves. The BSON bytes and type can be assumed to be valid. UnmarshalBSONValue must copy the BSON value bytes if it wishes to retain the data after returning.

type Zeroer Uses

type Zeroer interface {
    IsZero() bool
}

Zeroer allows custom struct types to implement a report of zero state. All struct types that don't implement Zeroer or where IsZero returns false are considered to be not zero.

Directories

PathSynopsis
bsoncodecPackage bsoncodec provides a system for encoding values to BSON representations and decoding values from BSON representations.
bsonrwPackage bsonrw contains abstractions for reading and writing BSON and BSON like types from sources.
bsonrw/bsonrwtest
bsontypePackage bsontype is a utility package that contains types for each BSON type and the a stringifier for the Type to enable easier debugging when working with BSON.
primitivePackage primitive contains types similar to Go primitives for BSON types can do not have direct Go primitive representations.

Package bson imports 15 packages (graph) and is imported by 63 packages. Updated 2019-01-08. Refresh now. Tools for package owners.