Documentation ¶
Overview ¶
Package bsonutil provides utilities for processing BSON data.
Index ¶
- Variables
- func ConvertBSONValueToLegacyExtJSON(x interface{}) (interface{}, error)
- func ConvertLegacyExtJSONDocumentToBSON(doc map[string]interface{}) error
- func ConvertLegacyExtJSONValueToBSON(x interface{}) (interface{}, error)
- func FindIntByKey(keyName string, document *bson.D) (int, error)
- func FindSubdocumentByKey(keyName string, document *bson.D) (bson.D, error)
- func FindValueByKey(keyName string, document *bson.D) (interface{}, error)
- func GetBSONValueAsLegacyExtJSON(x interface{}) (interface{}, error)
- func GetExtendedBsonD(doc bson.D) (bson.D, error)
- func MakeSortString(sortObj bson.D) ([]string, error)
- func ParseLegacyExtJSONValue(jsonValue interface{}) (interface{}, error)
- func ParseSpecialKeys(special interface{}) (interface{}, error)
- type MarshalD
Constants ¶
This section is empty.
Variables ¶
var ErrNoSuchField = errors.New("no such field")
Functions ¶
func ConvertBSONValueToLegacyExtJSON ¶
func ConvertBSONValueToLegacyExtJSON(x interface{}) (interface{}, error)
ConvertBSONValueToLegacyExtJSON 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 ConvertLegacyExtJSONDocumentToBSON ¶
ConvertLegacyExtJSONDocumentToBSON 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 ConvertLegacyExtJSONValueToBSON ¶
func ConvertLegacyExtJSONValueToBSON(x interface{}) (interface{}, error)
ConvertLegacyExtJSONValueToBSON walks through a document or an array and replaces any extended JSON value with its corresponding BSON type.
func FindIntByKey ¶
FindIntByKey returns the value of keyName in the document as an int for either int32 or int64 underlying type.
func FindSubdocumentByKey ¶
FindSubdocumentByKey returns the value of keyName in document as a document. Returns an error if keyName is not found in the top-level of the document, or if it is found but its value is not a document.
func FindValueByKey ¶
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 GetBSONValueAsLegacyExtJSON ¶
func GetBSONValueAsLegacyExtJSON(x interface{}) (interface{}, error)
GetBSONValueAsLegacyExtJSON is equivalent to ConvertBSONValueToLegacyExtJSON, but does not mutate its argument.
func GetExtendedBsonD ¶
GetExtendedBsonD iterates through the document and returns a bson.D that adds type information for each key in document.
func MakeSortString ¶
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 ParseLegacyExtJSONValue ¶
func ParseLegacyExtJSONValue(jsonValue interface{}) (interface{}, error)
ParseLegacyExtJSONValue 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. (uses legacy extJSON parser)
Types ¶
type MarshalD ¶
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 ¶
MarshalJSON makes the MarshalD type usable by the encoding/json package.