dskld5423 2016-01-13 12:55
浏览 72
已采纳

Golang Couchbase Gocb.RemoveOp-不删除所有

I think I did a silly mistake somewhere, but could not figure where for long time already :( The code is rough, I just testing things. It deletes, but by some reasons not all documents, I have rewritten to delete it all one by one, and that went OK. I use official package for Couchbase http://github.com/couchbase/gocb Here is code:

var items []gocb.BulkOp
myQuery := gocb.NewN1qlQuery([Selecting ~ 283k documents from 1.5mln])
rows, err := myBucket.ExecuteN1qlQuery(myQuery, nil)
checkErr(err)
var idToDelete map[string]interface{}

for rows.Next(&idToDelete) {
    items = append(items, &gocb.RemoveOp{Key: idToDelete["id"].(string)})
}

if err := rows.Close(); err != nil {
    fmt.Println(err.Error())
}
if err := myBucket.Do(items);err != nil {
    fmt.Println(err.Error())
}

This way it deleted ~70k documents, I run it again it got deleted 43k more..

Then I just let it delete one by one, and it worked fine:

//var items []gocb.BulkOp
myQuery := gocb.NewN1qlQuery([Selecting ~ 180k documents from ~1.3mln])
rows, err := myBucket.ExecuteN1qlQuery(myQuery, nil)
checkErr(err)
var idToDelete map[string]interface{}
for rows.Next(&idToDelete) {
  //items = append(items, &gocb.RemoveOp{Key: idToDelete["id"].(string)})
  _, err := myBucket.Remove(idToDelete["id"].(string), 0)
  checkErr(err)
}

if err := rows.Close(); err != nil {
  fmt.Println(err.Error())
}
//err = myBucket.Do(items)
  • 写回答

1条回答 默认 最新

  • duanchen7401 2016-01-19 02:55
    关注

    By default, queries against N1QL use a consistency level called 'request plus'. Thus, your second time running the program to query will use whatever index update is valid at the time of the query, rather than considering all of your previous mutations by waiting until the index is up to date. You can read more about this in Couchbase's Developer Guide and it looks like the you'll want to add the RequestPlus parameter to your myquery through the consistency method on the query.

    This kind of eventually consistent secondary indexing and the flexibility is pretty powerful because it gives you as a developer the ability to decide what level of consistency you want to pay for since index recalculations have a cost.

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

报告相同问题?

悬赏问题

  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档