2015-11-10 12:34
浏览 157

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 (
    as ""
   /// "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 {

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

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

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, 0xc20803b020, 0xc208052101, 0x0, 0x0, 0x0)
    /Users/milos/Downloads/golang/src/ +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 {
if err := iter.Close(); err != nil {
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhei2002 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.

    打赏 评论

相关推荐 更多相似问题