Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
在couchbase中批量插入_Couchbase - Fatal编程技术网

在couchbase中批量插入

在couchbase中批量插入,couchbase,Couchbase,我想将10000数据插入couchbase,但只成功插入了部分数据。我尝试过几次,每次成功插入的数据数量都不一样 如何将所有数据插入couchbase bucket, _ := myCluster.OpenBucket("test", "") for i := 0; i < 10000; i++ { s := strconv.Itoa(i) batch = append(batch, &gocb.ReplaceOp{Key: s, Value: "test"}) }

我想将
10000
数据插入
couchbase
,但只成功插入了部分数据。我尝试过几次,每次成功插入的数据数量都不一样

如何将所有数据插入
couchbase

bucket, _ := myCluster.OpenBucket("test", "")
for i := 0; i < 10000; i++ {
    s := strconv.Itoa(i)
    batch = append(batch, &gocb.ReplaceOp{Key: s, Value: "test"})
}

err = bucket.Do(batch)
bucket,\:=myCluster.OpenBucket(“test”,“”)
对于i:=0;i<10000;i++{
s:=strconv.Itoa(一)
batch=append(batch,&gocb.ReplaceOp{Key:s,Value:“test”})
}
err=bucket.Do(批处理)
有两张关于水桶的照片

操作前铲斗:

操作后的铲斗:


您可以尝试动态编写这种形式的长N1QL查询,但时间更长:

INSERT INTO test(KEY, VALUE) VALUES ("1", {"a": 1}), ("2", {"a": 2}), ("3", {"a": 3}) 

谢谢。我要用这种方法试试。我已经找到了我的部分数据插入失败的问题的答案。