...

Package bsonoptions

import "go.mongodb.org/mongo-driver/bson/bsonoptions"
Overview
Index

Overview ▾

Package bsonoptions defines the optional configurations for the BSON codecs.

Index ▾

type ByteSliceCodecOptions
    func ByteSliceCodec() *ByteSliceCodecOptions
    func MergeByteSliceCodecOptions(opts ...*ByteSliceCodecOptions) *ByteSliceCodecOptions
    func (bs *ByteSliceCodecOptions) SetEncodeNilAsEmpty(b bool) *ByteSliceCodecOptions
type EmptyInterfaceCodecOptions
    func EmptyInterfaceCodec() *EmptyInterfaceCodecOptions
    func MergeEmptyInterfaceCodecOptions(opts ...*EmptyInterfaceCodecOptions) *EmptyInterfaceCodecOptions
    func (e *EmptyInterfaceCodecOptions) SetDecodeBinaryAsSlice(b bool) *EmptyInterfaceCodecOptions
type MapCodecOptions
    func MapCodec() *MapCodecOptions
    func MergeMapCodecOptions(opts ...*MapCodecOptions) *MapCodecOptions
    func (t *MapCodecOptions) SetDecodeZerosMap(b bool) *MapCodecOptions
    func (t *MapCodecOptions) SetEncodeKeysWithStringer(b bool) *MapCodecOptions
    func (t *MapCodecOptions) SetEncodeNilAsEmpty(b bool) *MapCodecOptions
type SliceCodecOptions
    func MergeSliceCodecOptions(opts ...*SliceCodecOptions) *SliceCodecOptions
    func SliceCodec() *SliceCodecOptions
    func (s *SliceCodecOptions) SetEncodeNilAsEmpty(b bool) *SliceCodecOptions
type StringCodecOptions
    func MergeStringCodecOptions(opts ...*StringCodecOptions) *StringCodecOptions
    func StringCodec() *StringCodecOptions
    func (t *StringCodecOptions) SetDecodeObjectIDAsHex(b bool) *StringCodecOptions
type StructCodecOptions
    func MergeStructCodecOptions(opts ...*StructCodecOptions) *StructCodecOptions
    func StructCodec() *StructCodecOptions
    func (t *StructCodecOptions) SetAllowUnexportedFields(b bool) *StructCodecOptions
    func (t *StructCodecOptions) SetDecodeDeepZeroInline(b bool) *StructCodecOptions
    func (t *StructCodecOptions) SetDecodeZeroStruct(b bool) *StructCodecOptions
    func (t *StructCodecOptions) SetEncodeOmitDefaultStruct(b bool) *StructCodecOptions
    func (t *StructCodecOptions) SetOverwriteDuplicatedInlinedFields(b bool) *StructCodecOptions
type TimeCodecOptions
    func MergeTimeCodecOptions(opts ...*TimeCodecOptions) *TimeCodecOptions
    func TimeCodec() *TimeCodecOptions
    func (t *TimeCodecOptions) SetUseLocalTimeZone(b bool) *TimeCodecOptions
type UIntCodecOptions
    func MergeUIntCodecOptions(opts ...*UIntCodecOptions) *UIntCodecOptions
    func UIntCodec() *UIntCodecOptions
    func (u *UIntCodecOptions) SetEncodeToMinSize(b bool) *UIntCodecOptions

Package files

byte_slice_codec_options.go doc.go empty_interface_codec_options.go map_codec_options.go slice_codec_options.go string_codec_options.go struct_codec_options.go time_codec_options.go uint_codec_options.go

type ByteSliceCodecOptions

ByteSliceCodecOptions represents all possible options for byte slice encoding and decoding.

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

type ByteSliceCodecOptions struct {
    EncodeNilAsEmpty *bool // Specifies if a nil byte slice should encode as an empty binary instead of null. Defaults to false.
}

func ByteSliceCodec

func ByteSliceCodec() *ByteSliceCodecOptions

ByteSliceCodec creates a new *ByteSliceCodecOptions

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

func MergeByteSliceCodecOptions

func MergeByteSliceCodecOptions(opts ...*ByteSliceCodecOptions) *ByteSliceCodecOptions

MergeByteSliceCodecOptions combines the given *ByteSliceCodecOptions into a single *ByteSliceCodecOptions in a last one wins fashion.

Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.

func (*ByteSliceCodecOptions) SetEncodeNilAsEmpty

func (bs *ByteSliceCodecOptions) SetEncodeNilAsEmpty(b bool) *ByteSliceCodecOptions

SetEncodeNilAsEmpty specifies if a nil byte slice should encode as an empty binary instead of null. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Encoder.NilByteSliceAsEmpty instead.

type EmptyInterfaceCodecOptions

EmptyInterfaceCodecOptions represents all possible options for interface{} encoding and decoding.

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

type EmptyInterfaceCodecOptions struct {
    DecodeBinaryAsSlice *bool // Specifies if Old and Generic type binarys should default to []slice instead of primitive.Binary. Defaults to false.
}

func EmptyInterfaceCodec

func EmptyInterfaceCodec() *EmptyInterfaceCodecOptions

EmptyInterfaceCodec creates a new *EmptyInterfaceCodecOptions

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

func MergeEmptyInterfaceCodecOptions

func MergeEmptyInterfaceCodecOptions(opts ...*EmptyInterfaceCodecOptions) *EmptyInterfaceCodecOptions

MergeEmptyInterfaceCodecOptions combines the given *EmptyInterfaceCodecOptions into a single *EmptyInterfaceCodecOptions in a last one wins fashion.

Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.

func (*EmptyInterfaceCodecOptions) SetDecodeBinaryAsSlice

func (e *EmptyInterfaceCodecOptions) SetDecodeBinaryAsSlice(b bool) *EmptyInterfaceCodecOptions

SetDecodeBinaryAsSlice specifies if Old and Generic type binarys should default to []slice instead of primitive.Binary. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Decoder.BinaryAsSlice instead.

type MapCodecOptions

MapCodecOptions represents all possible options for map encoding and decoding.

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

type MapCodecOptions struct {
    DecodeZerosMap   *bool // Specifies if the map should be zeroed before decoding into it. Defaults to false.
    EncodeNilAsEmpty *bool // Specifies if a nil map should encode as an empty document instead of null. Defaults to false.
    // Specifies how keys should be handled. If false, the behavior matches encoding/json, where the encoding key type must
    // either be a string, an integer type, or implement bsoncodec.KeyMarshaler and the decoding key type must either be a
    // string, an integer type, or implement bsoncodec.KeyUnmarshaler. If true, keys are encoded with fmt.Sprint() and the
    // encoding key type must be a string, an integer type, or a float. If true, the use of Stringer will override
    // TextMarshaler/TextUnmarshaler. Defaults to false.
    EncodeKeysWithStringer *bool
}

func MapCodec

func MapCodec() *MapCodecOptions

MapCodec creates a new *MapCodecOptions

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

func MergeMapCodecOptions

func MergeMapCodecOptions(opts ...*MapCodecOptions) *MapCodecOptions

MergeMapCodecOptions combines the given *MapCodecOptions into a single *MapCodecOptions in a last one wins fashion.

Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.

func (*MapCodecOptions) SetDecodeZerosMap

func (t *MapCodecOptions) SetDecodeZerosMap(b bool) *MapCodecOptions

SetDecodeZerosMap specifies if the map should be zeroed before decoding into it. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Decoder.ZeroMaps instead.

func (*MapCodecOptions) SetEncodeKeysWithStringer

func (t *MapCodecOptions) SetEncodeKeysWithStringer(b bool) *MapCodecOptions

SetEncodeKeysWithStringer specifies how keys should be handled. If false, the behavior matches encoding/json, where the encoding key type must either be a string, an integer type, or implement bsoncodec.KeyMarshaler and the decoding key type must either be a string, an integer type, or implement bsoncodec.KeyUnmarshaler. If true, keys are encoded with fmt.Sprint() and the encoding key type must be a string, an integer type, or a float. If true, the use of Stringer will override TextMarshaler/TextUnmarshaler. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Encoder.StringifyMapKeysWithFmt instead.

func (*MapCodecOptions) SetEncodeNilAsEmpty

func (t *MapCodecOptions) SetEncodeNilAsEmpty(b bool) *MapCodecOptions

SetEncodeNilAsEmpty specifies if a nil map should encode as an empty document instead of null. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Encoder.NilMapAsEmpty instead.

type SliceCodecOptions

SliceCodecOptions represents all possible options for slice encoding and decoding.

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

type SliceCodecOptions struct {
    EncodeNilAsEmpty *bool // Specifies if a nil slice should encode as an empty array instead of null. Defaults to false.
}

func MergeSliceCodecOptions

func MergeSliceCodecOptions(opts ...*SliceCodecOptions) *SliceCodecOptions

MergeSliceCodecOptions combines the given *SliceCodecOptions into a single *SliceCodecOptions in a last one wins fashion.

Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.

func SliceCodec

func SliceCodec() *SliceCodecOptions

SliceCodec creates a new *SliceCodecOptions

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

func (*SliceCodecOptions) SetEncodeNilAsEmpty

func (s *SliceCodecOptions) SetEncodeNilAsEmpty(b bool) *SliceCodecOptions

SetEncodeNilAsEmpty specifies if a nil slice should encode as an empty array instead of null. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Encoder.NilSliceAsEmpty instead.

type StringCodecOptions

StringCodecOptions represents all possible options for string encoding and decoding.

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

type StringCodecOptions struct {
    DecodeObjectIDAsHex *bool // Specifies if we should decode ObjectID as the hex value. Defaults to true.
}

func MergeStringCodecOptions

func MergeStringCodecOptions(opts ...*StringCodecOptions) *StringCodecOptions

MergeStringCodecOptions combines the given *StringCodecOptions into a single *StringCodecOptions in a last one wins fashion.

Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.

func StringCodec

func StringCodec() *StringCodecOptions

StringCodec creates a new *StringCodecOptions

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

func (*StringCodecOptions) SetDecodeObjectIDAsHex

func (t *StringCodecOptions) SetDecodeObjectIDAsHex(b bool) *StringCodecOptions

SetDecodeObjectIDAsHex specifies if object IDs should be decoded as their hex representation. If false, a string made from the raw object ID bytes will be used. Defaults to true.

Deprecated: Decoding object IDs as raw bytes will not be supported in Go Driver 2.0.

type StructCodecOptions

StructCodecOptions represents all possible options for struct encoding and decoding.

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

type StructCodecOptions struct {
    DecodeZeroStruct                 *bool // Specifies if structs should be zeroed before decoding into them. Defaults to false.
    DecodeDeepZeroInline             *bool // Specifies if structs should be recursively zeroed when a inline value is decoded. Defaults to false.
    EncodeOmitDefaultStruct          *bool // Specifies if default structs should be considered empty by omitempty. Defaults to false.
    AllowUnexportedFields            *bool // Specifies if unexported fields should be marshaled/unmarshaled. Defaults to false.
    OverwriteDuplicatedInlinedFields *bool // Specifies if fields in inlined structs can be overwritten by higher level struct fields with the same key. Defaults to true.
}

func MergeStructCodecOptions

func MergeStructCodecOptions(opts ...*StructCodecOptions) *StructCodecOptions

MergeStructCodecOptions combines the given *StructCodecOptions into a single *StructCodecOptions in a last one wins fashion.

Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.

func StructCodec

func StructCodec() *StructCodecOptions

StructCodec creates a new *StructCodecOptions

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

func (*StructCodecOptions) SetAllowUnexportedFields

func (t *StructCodecOptions) SetAllowUnexportedFields(b bool) *StructCodecOptions

SetAllowUnexportedFields specifies if unexported fields should be marshaled/unmarshaled. Defaults to false.

Deprecated: AllowUnexportedFields does not work on recent versions of Go and will not be supported in Go Driver 2.0.

func (*StructCodecOptions) SetDecodeDeepZeroInline

func (t *StructCodecOptions) SetDecodeDeepZeroInline(b bool) *StructCodecOptions

SetDecodeDeepZeroInline specifies if structs should be zeroed before decoding into them. Defaults to false.

Deprecated: DecodeDeepZeroInline will not be supported in Go Driver 2.0.

func (*StructCodecOptions) SetDecodeZeroStruct

func (t *StructCodecOptions) SetDecodeZeroStruct(b bool) *StructCodecOptions

SetDecodeZeroStruct specifies if structs should be zeroed before decoding into them. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Decoder.ZeroStructs instead.

func (*StructCodecOptions) SetEncodeOmitDefaultStruct

func (t *StructCodecOptions) SetEncodeOmitDefaultStruct(b bool) *StructCodecOptions

SetEncodeOmitDefaultStruct specifies if default structs should be considered empty by omitempty. A default struct has all its values set to their default value. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Encoder.OmitZeroStruct instead.

func (*StructCodecOptions) SetOverwriteDuplicatedInlinedFields

func (t *StructCodecOptions) SetOverwriteDuplicatedInlinedFields(b bool) *StructCodecOptions

SetOverwriteDuplicatedInlinedFields specifies if inlined struct fields can be overwritten by higher level struct fields with the same bson key. When true and decoding, values will be written to the outermost struct with a matching key, and when encoding, keys will have the value of the top-most matching field. When false, decoding and encoding will error if there are duplicate keys after the struct is inlined. Defaults to true.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Encoder.ErrorOnInlineDuplicates instead.

type TimeCodecOptions

TimeCodecOptions represents all possible options for time.Time encoding and decoding.

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

type TimeCodecOptions struct {
    UseLocalTimeZone *bool // Specifies if we should decode into the local time zone. Defaults to false.
}

func MergeTimeCodecOptions

func MergeTimeCodecOptions(opts ...*TimeCodecOptions) *TimeCodecOptions

MergeTimeCodecOptions combines the given *TimeCodecOptions into a single *TimeCodecOptions in a last one wins fashion.

Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.

func TimeCodec

func TimeCodec() *TimeCodecOptions

TimeCodec creates a new *TimeCodecOptions

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

func (*TimeCodecOptions) SetUseLocalTimeZone

func (t *TimeCodecOptions) SetUseLocalTimeZone(b bool) *TimeCodecOptions

SetUseLocalTimeZone specifies if we should decode into the local time zone. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Decoder.UseLocalTimeZone instead.

type UIntCodecOptions

UIntCodecOptions represents all possible options for uint encoding and decoding.

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

type UIntCodecOptions struct {
    EncodeToMinSize *bool // Specifies if all uints except uint64 should be decoded to minimum size bsontype. Defaults to false.
}

func MergeUIntCodecOptions

func MergeUIntCodecOptions(opts ...*UIntCodecOptions) *UIntCodecOptions

MergeUIntCodecOptions combines the given *UIntCodecOptions into a single *UIntCodecOptions in a last one wins fashion.

Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a single options struct instead.

func UIntCodec

func UIntCodec() *UIntCodecOptions

UIntCodec creates a new *UIntCodecOptions

Deprecated: Use the bson.Encoder and bson.Decoder configuration methods to set the desired BSON marshal and unmarshal behavior instead.

func (*UIntCodecOptions) SetEncodeToMinSize

func (u *UIntCodecOptions) SetEncodeToMinSize(b bool) *UIntCodecOptions

SetEncodeToMinSize specifies if all uints except uint64 should be decoded to minimum size bsontype. Defaults to false.

Deprecated: Use go.mongodb.org/mongo-driver/bson.Encoder.IntMinSize instead.