1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
func (a *Address) UnmarshalBSONValue(t bsontype.Type, data []byte) error {
if s, _, ok := bsoncore.ReadString(data); ok {
a.Address = s
return nil
}
if t != bson.TypeEmbeddedDocument {
return fmt.Errorf("expected embedded document, got BSON type: %v", t)
}
var doc bson.D
if err := bson.Unmarshal(data, &doc); err != nil {
return fmt.Errorf("error unmarshaling embedded document: %v", err)
}
for _, elem := range doc {
switch elem.Key {
// List down the sub field, if Neeed to read
case "address":
a.Address = elem.Value.(string)
case "kec":
a.Kec = elem.Value.(string)
case "kel":
a.Kel = elem.Value.(string)
}
}
return nil
}
|