util

package
v0.0.0-...-6524a5b Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

The util package provides handy tools that are used by the gomongo package as well as by the implementation of the gomongo package. You can do quick conversions from string to primtive.ObjectID for use in custom queries for example.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintJson

func PrintJson(d interface{})

Helper function for debugging pipelines by decoding them into json. You can take the JSON use it to query the database directly for testing purposes.

func PtrBool

func PtrBool(val bool) *bool

Returns a pointer to a provided bool value. Used mainly by internal gomongo packages.

func PtrInt

func PtrInt(val int) *int

Returns a pointer to a provided int value. Used mainly by internal gomongo packages.

func PtrObjectIdSlice

func PtrObjectIdSlice(objectId primitive.ObjectID) *[]primitive.ObjectID

Returns a pointer to a slice from a provided primtive.ObjectID. Used mainly by internal gomongo packages.

func PtrString

func PtrString(val string) *string

Returns a pointer to a provided string value. Used mainly by internal gomongo packages.

func PtrTimeNow

func PtrTimeNow() *time.Time

Returns a pointer to a the current time value. Used mainly by internal gomongo packages.

func StringToObjectId

func StringToObjectId(id string) primitive.ObjectID

Converts a string to a primitive.ObjectID. If there is an error in the conversion it will return a new ObjectID generated from the current time.

func StringsToObjectId

func StringsToObjectId(ids []string) []primitive.ObjectID

Converts a slice of strings to a slice of primitive.ObjectID. If there is an error in the conversion of any one of the strings, it will return a new ObjectID generated from the current time.

Types

type OptionalString

type OptionalString string

Normally when unmarshalling bson into a struct, all values that are missing from the database are initialized as their zero value (with the exception of pointers whose zero value is nil). If a value is specified in the struct but is missing in the database it will throw an error. The OptionalString type allows you specify strings that can be considered optional. Fields that are strings and are not provided by the database are initialized as their zero value.

func (*OptionalString) IsZero

func (o *OptionalString) IsZero() bool

Helper function for determining if an optional string is set to it's zero value.

func (*OptionalString) UnmarshalBSONValue

func (o *OptionalString) UnmarshalBSONValue(t bsontype.Type, data []byte) error

Jump to

Keyboard shortcuts

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