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 ¶
- func PrintJson(d interface{})
- func PtrBool(val bool) *bool
- func PtrInt(val int) *int
- func PtrObjectIdSlice(objectId primitive.ObjectID) *[]primitive.ObjectID
- func PtrString(val string) *string
- func PtrTimeNow() *time.Time
- func StringToObjectId(id string) primitive.ObjectID
- func StringsToObjectId(ids []string) []primitive.ObjectID
- type OptionalString
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 ¶
Returns a pointer to a provided bool value. Used mainly by internal gomongo packages.
func PtrObjectIdSlice ¶
Returns a pointer to a slice from a provided primtive.ObjectID. Used mainly by internal gomongo packages.
func PtrString ¶
Returns a pointer to a provided string value. Used mainly by internal gomongo packages.
func PtrTimeNow ¶
Returns a pointer to a the current time value. Used mainly by internal gomongo packages.
func StringToObjectId ¶
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 ¶
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