Encode and decode to map[string]interface{}. This isn't ideal, because the mongo client encodes/decodes a second time. TODO(jba): Benchmark the double decode to see if it's worth trying to avoid it. This code is copied from memdocstore/codec.go, except for special treatment of primitive.Binary.
(doc driver.Document, lowercaseFields bool)
| 32 | // primitive.Binary. |
| 33 | |
| 34 | func encodeDoc(doc driver.Document, lowercaseFields bool) (map[string]interface{}, error) { |
| 35 | e := encoder{lowercaseFields: lowercaseFields} |
| 36 | if err := doc.Encode(&e); err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | return e.val.(map[string]interface{}), nil |
| 40 | } |
| 41 | |
| 42 | func encodeValue(x interface{}) (interface{}, error) { |
| 43 | var e encoder |