...

/

CouchbaseTemplate and Direct Operations

CouchbaseTemplate and Direct Operations

Learn about Spring Data’s CouchbaseTemplate to perform direct operations.

The CouchbaseTemplate class

The CouchbaseTemplate class in Spring Data Couchbase provides simplified APIs for interacting with the Couchbase database, allowing the performance of CRUD operations and execution of queries on Couchbase documents.

Create and update operations

We use the upsertById method of the CouchbaseTemplate to easily create or update documents based on their IDs, simplifying data management with Couchbase.

Press + to interact
// Create an Entity
Author morganHousel = new Author();
morganHousel.setFirstName("Morgan");
morganHousel.setLastName("Housel");
// Upsert it
couchbaseTemplate.upsertById(Author.class).one(morganHousel);

Here’s an explanation of the code:

  • Lines 2–4: We create the Author object and set properties like firstName and lastName.

  • Line 7: We use the ...