summaryrefslogtreecommitdiff
path: root/common/json/json_format.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/json/json_format.go')
-rw-r--r--common/json/json_format.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/common/json/json_format.go b/common/json/json_format.go
index 90f7ad75778..ebe8eb9d2d4 100644
--- a/common/json/json_format.go
+++ b/common/json/json_format.go
@@ -13,7 +13,7 @@ func (b BinData) MarshalJSON() ([]byte, error) {
return []byte(data), nil
}
-func (js Javascript) MarshalJSON() ([]byte, error) {
+func (js JavaScript) MarshalJSON() ([]byte, error) {
return []byte(js.Code), nil
}
@@ -43,8 +43,9 @@ func (d DBRef) MarshalJSON() ([]byte, error) {
var dbChunk []byte
if d.Database != "" {
- dbChunk = []byte(fmt.Sprintf(`, "$db": "%v" }`, d.Database))
+ dbChunk = []byte(fmt.Sprintf(`, "$db": "%v" `, d.Database))
}
+ dbChunk = append(dbChunk, '}')
data := make([]byte, len(refChunk)+len(idChunk)+len(dbChunk))
copy(data, refChunk)
@@ -54,6 +55,17 @@ func (d DBRef) MarshalJSON() ([]byte, error) {
return data, nil
}
+func (d DBPointer) MarshalJSON() ([]byte, error) {
+ // Convert the $id field to JSON
+ idChunk, err := Marshal(d.Id)
+ if err != nil {
+ return nil, err
+ }
+
+ data := append([]byte(fmt.Sprintf(`{ "$ref": "%v", "$id": `, d.Namespace)), idChunk...)
+ return append(data, '}'), nil
+}
+
func (_ MinKey) MarshalJSON() ([]byte, error) {
data := `{ "$minKey": 1 }`
return []byte(data), nil