Mix mutations

Mix and match mutation operations such as inserting rows and deleting a column.

Code sample


To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::Status;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::string const& key, std::string const& family,
   std::string const& old_name, std::string const& new_name) {
  StatusOr<std::pair<bool, cbt::Row>> row =
      table.ReadRow(key, cbt::Filter::ColumnName(family, old_name));

  if (!row) throw std::move(row).status();
  if (!row->first) throw std::runtime_error("Cannot find row " + key);

  cbt::SingleRowMutation mutation(key);
  for (auto const& cell : row->second.cells()) {
    // Create a new cell
    auto timestamp_in_milliseconds =
    mutation.emplace_back(cbt::SetCell(family, new_name,
  mutation.emplace_back(cbt::DeleteFromColumn("fam", old_name));

  google::cloud::Status status = table.Apply(std::move(mutation));
  if (!status.ok()) throw std::runtime_error(status.message());
  std::cout << "Row successfully updated\n";

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.