dongleibeng5602 2015-11-10 12:34
浏览 183
已采纳

Aerospike Golang客户端的putObject方法使我感到恐慌:反射:调用map Value上的reflect.Value.Elem

I'm trying to save a the results from MongoDB into AeroSpike. I'm using the MGO client for Mongodb. The code is the following :

package main

import (
    "log"
    "flag"
    "fmt"
    ///"reflect"
    "gopkg.in/mgo.v2"
    "gopkg.in/mgo.v2/bson"
    as "github.com/aerospike/aerospike-client-go"
   /// "encoding/json"
)


/*
Iterating through the results
 */
 results := make(map[string]interface{})
 iter := c.Find(nil).Iter()
for iter.Next(&results) {

    tmp := make(map[string]interface{})
    b, _ := bson.Marshal(results)
    bson.Unmarshal(b, &tmp)
        log.Println("func (interface, interface):",  tmp["_id"])
/*
Aerospike Key
 */
        key, err := as.NewKey(*Namespace, *Set, "LIST")
if err != nil {
    log.Fatal(err)
}

/*
Saving to aerospike
 */
client.PutObject(WritePolicy, key, tmp)

}
if err := iter.Close(); err != nil {
   fmt.Println(err)
}

I get the following error from Aerospike :

panic: reflect: call of reflect.Value.Elem on map Value

goroutine 1 [running]:
reflect.Value.Elem(0x24dd40, 0xc20803b020, 0x15, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/1.4.2/libexec/src/reflect/value.go:703 +0x1d5
github.com/aerospike/aerospike-client-go.marshal(0x24dd40, 0xc20803b020, 0xc208052101, 0x0, 0x0, 0x0)
    /Users/milos/Downloads/golang/src/github.com/aerospike/aerospike-client-go/marshal.go:143 +0xa1

I have turned to google and had no luck with this.

For a sanity test I have ran the following to see if the struct saves into AeroSpike and it does save.

 type OBJECT struct {
    Price  int
    DBName string
}

obj := &OBJECT{198, "Jack Shaftoe and Company"}
 errr := client.PutObject(WritePolicy, key, obj)
if errr != nil {
    log.Fatal(errr)
}
}
if err := iter.Close(); err != nil {
   fmt.Println(err)
}
  • 写回答

1条回答 默认 最新

  • 普通网友 2015-11-10 19:30
    关注

    You are trying to save a map into aerospike as oppose to a struct.

    I think that your best option is to encapsulate the map inside a struct.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号