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.

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

报告相同问题?