bsonuuid

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 6 Imported by: 0

README

UUID Support for BSON Serialization in Mongo Go Driver


Motivation

While working with a legacy system we are indexing a fairly large amount of data into a time series collection where the IDs are UUID types. Our first instinct was to use strings as they are easier to work around with the go drivers for MongoDB, but we can cut our index sizes considerably using the binary representation. Thus, bson-uuid was born.

Installation
go get -u github.com/vonix-networks/bsonuuid
Deployment

There is a builder for a quick replacement if this is the only change to the registry needed:

client, err := mongo.Connect(context.Background(),
    options.Client().ApplyURI("uri"),
    options.Client().SetRegistry(bsonuuid.BuildRegistry()))

This will enable serialization from and to the standard UUID MongoDB type (specifically the binary subtype 0x04). It will also attempt to automatically parse strings.

Change History
  • v0.1.0 - Initial release
  • v0.1.1 - Fixed module cache issues

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TypeUUID = reflect.TypeOf(uuid.UUID{})

Functions

func BuildRegistry

func BuildRegistry() *bsoncodec.Registry

func UUIDDecodeValue

func UUIDDecodeValue(_ bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

UUIDDecodeValue attempts to unmarshal a string or a binary with subtype 0x00 (generic) or 0x04 (uuid) into an uuid.UUID type.

func UUIDEncodeValue

func UUIDEncodeValue(_ bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error

UUIDEncodeValue attempts to marshal an uuid.UUID type into a MongoDB binary uuid type.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL