startKey := []byte("key1") endKey := []byte("key5") b := db.NewBatch() b.DelRange(startKey, endKey) err := db.Write(b)
startKey := []byte("users:") endKey := []byte("users:zzz") b := db.NewBatch() b.DelRange(startKey, endKey) err := db.Write(b)In this example, we are deleting all the key-value pairs in the range between "users:" and "users:zzz". This is useful if we want to delete a subset of keys that share a common prefix. Overall, the Batch DelRange method is a powerful tool in CockroachDB for batch deletion of multiple key-value pairs. It is part of the github.com.cockroachdb.cockroach.client package library.