mongo-driver: go.mongodb.org/mongo-driver/bson/primitive Index | Files

package primitive

import "go.mongodb.org/mongo-driver/bson/primitive"

Package primitive contains types similar to Go primitives for BSON types can do not have direct Go primitive representations.

Index

Package Files

decimal.go objectid.go primitive.go

Variables

var ErrInvalidHex = errors.New("the provided hex string is not a valid ObjectID")

ErrInvalidHex indicates that a hex string cannot be converted to an ObjectID.

func CompareTimestamp Uses

func CompareTimestamp(tp, tp2 Timestamp) int

CompareTimestamp returns an integer comparing two Timestamps, where T is compared first, followed by I. Returns 0 if tp = tp2, 1 if tp > tp2, -1 if tp < tp2.

type A Uses

type A []interface{}

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:

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

type Binary Uses

type Binary struct {
    Subtype byte
    Data    []byte
}

Binary represents a BSON binary value.

func (Binary) Equal Uses

func (bp Binary) Equal(bp2 Binary) bool

Equal compaes bp to bp2 and returns true is the are equal.

type CodeWithScope Uses

type CodeWithScope struct {
    Code  JavaScript
    Scope interface{}
}

CodeWithScope represents a BSON JavaScript code with scope value.

func (CodeWithScope) String Uses

func (cws CodeWithScope) String() string

type D Uses

type D []E

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:

primitive.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.

func (D) Map Uses

func (d D) Map() M

Map creates a map from the elements of the D.

type DBPointer Uses

type DBPointer struct {
    DB      string
    Pointer ObjectID
}

DBPointer represents a BSON dbpointer value.

func (DBPointer) Equal Uses

func (d DBPointer) Equal(d2 DBPointer) bool

Equal compaes d to d2 and returns true is the are equal.

func (DBPointer) String Uses

func (d DBPointer) String() string

type DateTime Uses

type DateTime int64

DateTime represents the BSON datetime value.

func NewDateTimeFromTime Uses

func NewDateTimeFromTime(t time.Time) DateTime

NewDateTimeFromTime creates a new DateTime from a Time.

func (DateTime) MarshalJSON Uses

func (d DateTime) MarshalJSON() ([]byte, error)

MarshalJSON marshal to time type

func (DateTime) Time Uses

func (d DateTime) Time() time.Time

Time returns the date as a time type.

type Decimal128 Uses

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

Decimal128 holds decimal128 BSON values.

func NewDecimal128 Uses

func NewDecimal128(h, l uint64) Decimal128

NewDecimal128 creates a Decimal128 using the provide high and low uint64s.

func ParseDecimal128 Uses

func ParseDecimal128(s string) (Decimal128, error)

ParseDecimal128 takes the given string and attempts to parse it into a valid Decimal128 value.

func (Decimal128) GetBytes Uses

func (d Decimal128) GetBytes() (uint64, uint64)

GetBytes returns the underlying bytes of the BSON decimal value as two uint16 values. The first contains the most first 8 bytes of the value and the second contains the latter.

func (Decimal128) String Uses

func (d Decimal128) String() string

String returns a string representation of the decimal value.

type E Uses

type E struct {
    Key   string
    Value interface{}
}

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

type JavaScript Uses

type JavaScript string

JavaScript represents a BSON JavaScript code value.

type M Uses

type M map[string]interface{}

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:

primitive.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 MaxKey Uses

type MaxKey struct{}

MaxKey represents the BSON maxkey value.

type MinKey Uses

type MinKey struct{}

MinKey represents the BSON minkey value.

type Null Uses

type Null struct{}

Null repreesnts the BSON null value.

type ObjectID Uses

type ObjectID [12]byte

ObjectID is the BSON ObjectID type.

var NilObjectID ObjectID

NilObjectID is the zero value for ObjectID.

func NewObjectID Uses

func NewObjectID() ObjectID

NewObjectID generates a new ObjectID.

func NewObjectIDFromTimestamp Uses

func NewObjectIDFromTimestamp(timestamp time.Time) ObjectID

NewObjectIDFromTimestamp generates a new ObjectID based on the given time.

func ObjectIDFromHex Uses

func ObjectIDFromHex(s string) (ObjectID, error)

ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a valid ObjectID.

func (ObjectID) Hex Uses

func (id ObjectID) Hex() string

Hex returns the hex encoding of the ObjectID as a string.

func (ObjectID) IsZero Uses

func (id ObjectID) IsZero() bool

IsZero returns true if id is the empty ObjectID.

func (ObjectID) MarshalJSON Uses

func (id ObjectID) MarshalJSON() ([]byte, error)

MarshalJSON returns the ObjectID as a string

func (ObjectID) String Uses

func (id ObjectID) String() string

func (ObjectID) Timestamp Uses

func (id ObjectID) Timestamp() time.Time

Timestamp extracts the time part of the ObjectId.

func (*ObjectID) UnmarshalJSON Uses

func (id *ObjectID) UnmarshalJSON(b []byte) error

UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 64 bytes long, it will be populated with the hex representation of the ObjectID. If the byte slice is twelve bytes long, it will be populated with the BSON representation of the ObjectID. Otherwise, it will return an error.

type Regex Uses

type Regex struct {
    Pattern string
    Options string
}

Regex represents a BSON regex value.

func (Regex) Equal Uses

func (rp Regex) Equal(rp2 Regex) bool

Equal compaes rp to rp2 and returns true is the are equal.

func (Regex) String Uses

func (rp Regex) String() string

type Symbol Uses

type Symbol string

Symbol represents a BSON symbol value.

type Timestamp Uses

type Timestamp struct {
    T   uint32
    I   uint32
}

Timestamp represents a BSON timestamp value.

func (Timestamp) Equal Uses

func (tp Timestamp) Equal(tp2 Timestamp) bool

Equal compaes tp to tp2 and returns true is the are equal.

type Undefined Uses

type Undefined struct{}

Undefined represents the BSON undefined value type.

Package primitive imports 12 packages (graph) and is imported by 91 packages. Updated 2019-06-01. Refresh now. Tools for package owners.