Moved from GitHub dgo/3
Posted by tyuwan:
I apologize, if this is not the correct place to post this. When I set facets with int(1) value it stored as float (1.000000). It’s perfectly fine if I post or query with HTTP
type GraphCollection struct {
Uid string `json:"uid"`
Weight []GraphNode `json:"weight,omitempty"`
}
type GraphNode struct {
Uid string `json:"uid"`
WeightFacets int64 `json:"weight|score,omitempty"`
}
data := GraphCollection{
Uid: cuid,
Weight: []GraphNode{
{
Uid: muid,
WeightFacets: 1,
},
},
}
ctx := context.Background()
dg, conn := dgraph.NewClient()
defer conn.Close()
pb, err := json.Marshal(data)
if err != nil {
log.Fatal(err)
}
_, err = dg.NewTxn().Mutate(ctx, &api.Mutation{SetJson: pb, CommitNow: true})
if err != nil {
log.Error(err)
}
marshal string:
{"uid":"0x9c6711","weight":[{"uid":"0x1053b2","weight|score":1}]}
q := fmt.Sprintf(`{
me(func: uid(0x9c6711)) {
weight @facets {
uid
}
}
}`)
txn := dg.NewTxn()
resp, err := txn.Query(ctx, q)
if err != nil {
log.Fatal(err)
}
log.Debug(string(resp.Json))
response:
{"me":[{"weight":[{"uid":"0x1053b2","weight|score":1.000000}]}]}
with error
json: cannot unmarshal number 1.000000 into Go struct field weight of type int