Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Aerospike Golang客户端putObject方法让我恐慌:reflect:调用映射值上的reflect.Value.Elem_Mongodb_Go_Aerospike - Fatal编程技术网

Mongodb Aerospike Golang客户端putObject方法让我恐慌:reflect:调用映射值上的reflect.Value.Elem

Mongodb Aerospike Golang客户端putObject方法让我恐慌:reflect:调用映射值上的reflect.Value.Elem,mongodb,go,aerospike,Mongodb,Go,Aerospike,我正试图将MongoDB的结果保存到AeroSpike中。我正在使用Mongodb的MGO客户端。代码如下: 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" )

我正试图将MongoDB的结果保存到AeroSpike中。我正在使用Mongodb的MGO客户端。代码如下:

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)
}
我从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
我求助于谷歌,但在这方面运气不佳

为了进行理智测试,我运行了以下命令,以查看该结构是否保存到AeroSpike中,并且是否保存

 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)
}

您正试图将贴图保存到aerospike中,以与结构相对


我认为最好的选择是将映射封装在结构中

你能在aerospike中插入一个简单的字符串吗?你应该加上,你使用的是哪个软件包。从它惊慌失措而不是返回解释错误的错误这一事实来看,这似乎是一个软件包错误。我正在迭代MongoDB集合,并尝试使用Aerospiks PutObject方法将文档保存到AeroSpike。@eden我做了一个健全性测试,structs确实保存到AeroSpike中。我用我用来保存数据的代码更新了这个问题AeroSpike@Ainar我用软件包更新了这个问题。