diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/bsonutil/converter.go | 4 | ||||
-rw-r--r-- | common/bsonutil/converter_test.go | 4 | ||||
-rw-r--r-- | common/json/json_format.go | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/common/bsonutil/converter.go b/common/bsonutil/converter.go index 17c44cb5fc2..3be732de332 100644 --- a/common/bsonutil/converter.go +++ b/common/bsonutil/converter.go @@ -96,7 +96,7 @@ func ConvertJSONValueToBSON(x interface{}) (interface{}, error) { } } -func convertKeys(v bson.M) (map[string]interface{}, error) { +func convertKeys(v bson.M) (bson.M, error) { for key, value := range v { jsonValue, err := ConvertBSONValueToJSON(value) if err != nil { @@ -157,7 +157,7 @@ func ConvertBSONValueToJSON(x interface{}) (interface{}, error) { return json.ObjectId(v.Hex()), nil case time.Time: // Date - return json.Date(v.UnixNano() / 1e6), nil + return json.Date(v.Unix()*1000 + int64(v.Nanosecond()/1e6)), nil case int64: // NumberLong return json.NumberLong(v), nil diff --git a/common/bsonutil/converter_test.go b/common/bsonutil/converter_test.go index ad4bed9ebeb..7d789bf38d8 100644 --- a/common/bsonutil/converter_test.go +++ b/common/bsonutil/converter_test.go @@ -59,11 +59,11 @@ func TestArraysBSONToJSON(t *testing.T) { So(err, ShouldBeNil) _jObj, ok := __jObj.([]interface{}) So(ok, ShouldBeTrue) - jObj, ok := _jObj[1].(map[string]interface{}) + jObj, ok := _jObj[1].(bson.M) So(ok, ShouldBeTrue) So(len(jObj), ShouldEqual, 2) So(jObj["a"], ShouldEqual, json.NumberLong(20)) - jjObj, ok := jObj["b"].(map[string]interface{}) + jjObj, ok := jObj["b"].(bson.M) So(ok, ShouldBeTrue) So(jjObj["c"], ShouldResemble, json.RegExp{"hi", "i"}) diff --git a/common/json/json_format.go b/common/json/json_format.go index ad0086fe032..41b362bca23 100644 --- a/common/json/json_format.go +++ b/common/json/json_format.go @@ -14,7 +14,7 @@ func (b BinData) MarshalJSON() ([]byte, error) { } func (js JavaScript) MarshalJSON() ([]byte, error) { - data := []byte(fmt.Sprintf(`{ "$code": "%v"`, js.Code)) + data := []byte(fmt.Sprintf(`{ "$code": %q`, js.Code)) scopeChunk := []byte{} if js.Scope != nil { |