bsonutil

package
v0.0.0-...-a15ebab Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package bsonutil provides utilities for processing BSON data.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSuchField = errors.New("no such field")

Functions

func ConvertBSONValueToJSON

func ConvertBSONValueToJSON(x interface{}) (interface{}, error)

ConvertBSONValueToJSON walks through a document or an array and converts any BSON value to its corresponding extended JSON type. It returns the converted JSON document and any error encountered.

func ConvertJSONDocumentToBSON

func ConvertJSONDocumentToBSON(doc map[string]interface{}) error

ConvertJSONDocumentToBSON iterates through the document map and converts JSON values to their corresponding BSON values. It also replaces any extended JSON type value (e.g. $date) with the corresponding BSON type.

func ConvertJSONValueToBSON

func ConvertJSONValueToBSON(x interface{}) (interface{}, error)

ConvertJSONValueToBSON walks through a document or an array and replaces any extended JSON value with its corresponding BSON type.

func FindValueByKey

func FindValueByKey(keyName string, document *bson.D) (interface{}, error)

FindValueByKey returns the value of keyName in document. If keyName is not found in the top-level of the document, ErrNoSuchField is returned as the error.

func GetExtendedBsonD

func GetExtendedBsonD(doc bson.D) (bson.D, error)

GetExtendedBsonD iterates through the document and returns a bson.D that adds type information for each key in document.

func MakeSortString

func MakeSortString(sortObj bson.D) ([]string, error)

MakeSortString takes a bson.D object and converts it to a slice of strings that can be used as the input args to mgo's .Sort(...) function. For example: {a:1, b:-1} -> ["+a", "-b"]

func ParseJSONValue

func ParseJSONValue(jsonValue interface{}) (interface{}, error)

ParseJSONValue takes any value generated by the json package and returns a BSON version of that value.

func ParseSpecialKeys

func ParseSpecialKeys(special interface{}) (interface{}, error)

ParseSpecialKeys takes a JSON document and inspects it for any extended JSON type (e.g $numberLong) and replaces any such values with the corresponding BSON type.

Types

type MarshalD

type MarshalD bson.D

MarshalD is a wrapper for bson.D that allows unmarshalling of bson.D with preserved order. Necessary for printing certain database commands.

func (MarshalD) MarshalJSON

func (md MarshalD) MarshalJSON() ([]byte, error)

MarshalJSON makes the MarshalD type usable by the encoding/json package.

Jump to

Keyboard shortcuts

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