Data getting misplaced to other keys while doing bulk insert


We are doing bulk operations with gocb/v2.
While inserting 10 documents in each bulk call we see that data is getting misplaced into other key.

var sellocPincodeDataBulk []gocb.BulkOp
for key, value := range MapData {
                        if key != value.FName+"#"+value.LName {
                        fmt.Println("Values is different from ID: ", key," " ,vaa
                        MapDataBulk = append(MapDataBulk, &gg
ocb.InsertOp{ID: key, Value: &value})
                        if count%10 == 0 && count != 0 {
                                err = Collection.Do(MapDataBulk, &gocbb
                                if err != nil {
                                        fmt.Println("ERRROR PERFORMING BULK INSEE
RT:", err)
                                } else {
                                        fmt.Println("inserted 10 docs for")
                                MapDataBulk = []gocb.BulkOp{}

When we do 1 doc insert with gocb.bulk{} it works fine. But when we insert 10 then it is misplacing one key’s data to other key.

My Doc key is a combination of LastName and FirstName which is also part of Doc Value So that I am able to find that data is getting misplaced.

Please let me know if you need any info.


Hi @akhilravuri2 what makes you say that the data is getting misplaced?

Also ensure that you are checking each op for errors after performing the batch, as shown at Choosing an API | Couchbase Docs. The key part being

	for _, batch := range batches {
		err := collection.Do(batch, nil)
		if err != nil {

		// Be sure to check each individual operation for errors too.
		for _, op := range batch {
			upsertOp := op.(*gocb.UpsertOp)
			if upsertOp.Err != nil {


Our Doc key is combination of LName and FName which are also part of document.

I just inserted batch of 10 docs once and checked key and value of document then we found out that FName in key and FName in Value is different. This happened for all the docs also. But while doing insertion one by one doc this MisMatch does not happen.


"Akhil#Ravuri": {
"FName": "Singh", // this should be "AKHIL"

We just added a log before inserting the doc but in the logs we see data is mapped correctly but when see data in the server it is misplaced.


Hi @akhilravuri2 I think that this probably has something to do with the way you are creating your MapBulkData. If you change the line

MapDataBulk = append(MapDataBulk, &gocb.InsertOp{ID: key, Value: &value})


MapDataBulk = append(MapDataBulk, &gocb.InsertOp{ID: key, Value: value})

i.e. you don’t use a pointer to value. Then I would expect this to work ok.

Thanks @chvck

It worked the issue was at &value.