Insert rows with mutate

Insert rows using mutate.

Code sample


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

namespace cbt = ::google::cloud::bigtable;
[](cbt::Table table) {
  // Write several rows in a single operation, each row has some trivial data.
  cbt::BulkMutation bulk;
  for (int i = 0; i != 5000; ++i) {
    // Note: This example uses sequential numeric IDs for simplicity, but
    // this can result in poor performance in a production application.
    // Since rows are stored in sorted order by key, sequential keys can
    // result in poor distribution of operations across nodes.
    // For more information about how to design a Bigtable schema for the
    // best performance, see the documentation:
    char buf[32];
    snprintf(buf, sizeof(buf), "key-%06d", i);
    cbt::SingleRowMutation mutation(buf);
        cbt::SetCell("fam", "col0", "value0-" + std::to_string(i)));
        cbt::SetCell("fam", "col1", "value1-" + std::to_string(i)));
  std::vector<cbt::FailedMutation> failures =
  if (failures.empty()) {
    std::cout << "All mutations applied successfully\n";
  // By default, the `table` object uses the `SafeIdempotentMutationPolicy`
  // which does not retry if any of the mutations fails and are
  // not-idempotent. In this example we simply print such failures, if any,
  // and ignore them otherwise.
  std::cerr << "The following mutations failed and were not retried:\n";
  for (auto const& f : failures) {
    std::cerr << "index[" << f.original_index() << "]=" << f.status() << "\n";

What's next

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