Documentation ¶
Overview ¶
Package primitive contains types similar to Go primitives for BSON types can do not have direct Go primitive representations.
Index ¶
Constants ¶
const ( MaxDecimal128Exp = 6111 MinDecimal128Exp = -6176 )
These constants are the maximum and minimum values for the exponent field in a decimal128 value.
Variables ¶
var ( ErrParseNaN = errors.New("cannot parse NaN as a *big.Int") ErrParseInf = errors.New("cannot parse Infinity as a *big.Int") ErrParseNegInf = errors.New("cannot parse -Infinity as a *big.Int") )
These errors are returned when an invalid value is parsed as a big.Int.
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.
Functions ¶
func CompareTimestamp ¶ added in v1.1.0
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.
Types ¶
type A ¶ added in v0.1.0
type A []interface{}
An A is an ordered representation of a BSON array.
Example usage:
bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}}
type Binary ¶
Binary represents a BSON binary value.
type CodeWithScope ¶
type CodeWithScope struct { Code JavaScript Scope interface{} }
CodeWithScope represents a BSON JavaScript code with scope value.
func (CodeWithScope) String ¶
func (cws CodeWithScope) String() string
type D ¶ added in v0.1.0
type D []E
D is an ordered representation of a BSON document. This type should be used when the order of the elements matters, such as MongoDB command documents. If the order of the elements does not matter, an M should be used instead.
Example usage:
bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}}
type DBPointer ¶
DBPointer represents a BSON dbpointer value.
type DateTime ¶
type DateTime int64
DateTime represents the BSON datetime value.
func NewDateTimeFromTime ¶ added in v1.1.0
NewDateTimeFromTime creates a new DateTime from a Time.
func (DateTime) MarshalJSON ¶ added in v1.0.0
MarshalJSON marshal to time type
func (*DateTime) UnmarshalJSON ¶ added in v1.4.0
UnmarshalJSON creates a primitive.DateTime from a JSON string.
type Decimal128 ¶ added in v0.1.0
type Decimal128 struct {
// contains filtered or unexported fields
}
Decimal128 holds decimal128 BSON values.
func NewDecimal128 ¶ added in v0.1.0
func NewDecimal128(h, l uint64) Decimal128
NewDecimal128 creates a Decimal128 using the provide high and low uint64s.
func ParseDecimal128 ¶ added in v0.1.0
func ParseDecimal128(s string) (Decimal128, error)
ParseDecimal128 takes the given string and attempts to parse it into a valid Decimal128 value.
func ParseDecimal128FromBigInt ¶ added in v1.2.0
func ParseDecimal128FromBigInt(bi *big.Int, exp int) (Decimal128, bool)
ParseDecimal128FromBigInt attempts to parse the given significand and exponent into a valid Decimal128 value.
func (Decimal128) BigInt ¶ added in v1.2.0
func (d Decimal128) BigInt() (bi *big.Int, exp int, err error)
BigInt returns significand as big.Int and exponent, bi * 10 ^ exp.
func (Decimal128) GetBytes ¶ added in v0.1.0
func (d Decimal128) GetBytes() (uint64, uint64)
GetBytes returns the underlying bytes of the BSON decimal value as two uint64 values. The first contains the most first 8 bytes of the value and the second contains the latter.
func (Decimal128) IsInf ¶ added in v1.2.0
func (d Decimal128) IsInf() int
IsInf returns:
+1 d == Infinity 0 other case -1 d == -Infinity
func (Decimal128) IsNaN ¶ added in v1.2.0
func (d Decimal128) IsNaN() bool
IsNaN returns whether d is NaN.
func (Decimal128) String ¶ added in v0.1.0
func (d Decimal128) String() string
String returns a string representation of the decimal value.
type E ¶ added in v0.1.0
type E struct { Key string Value interface{} }
E represents a BSON element for a D. It is usually used inside a D.
type M ¶ added in v0.1.0
type M map[string]interface{}
M is an unordered representation of a BSON document. This type should be used when the order of the elements does not matter. This type is handled as a regular map[string]interface{} when encoding and decoding. Elements will be serialized in an undefined, random order. If the order of the elements matters, a D should be used instead.
Example usage:
bson.M{"foo": "bar", "hello": "world", "pi": 3.14159}.
type ObjectID ¶ added in v0.1.0
type ObjectID [12]byte
ObjectID is the BSON ObjectID type.
var NilObjectID ObjectID
NilObjectID is the zero value for ObjectID.
func NewObjectID ¶ added in v0.1.0
func NewObjectID() ObjectID
NewObjectID generates a new ObjectID.
func NewObjectIDFromTimestamp ¶ added in v1.1.0
NewObjectIDFromTimestamp generates a new ObjectID based on the given time.
func ObjectIDFromHex ¶ added in v0.1.0
ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a valid ObjectID.
func (ObjectID) MarshalJSON ¶ added in v0.1.0
MarshalJSON returns the ObjectID as a string
func (*ObjectID) UnmarshalJSON ¶ added in v0.1.0
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 ¶
Regex represents a BSON regex value.