Skip to content

Couchbase Module

Couchbase is a distributed document database with a powerful search engine and in-built operational and analytical capabilities. It brings the power of NoSQL to the edge and provides fast, efficient bidirectional synchronization of data between the edge and the cloud.

Install

npm install @testcontainers/couchbase --save-dev

Examples

const upsertAndGet = async (
  bucket: Bucket,
  key: string,
  value: Record<string, string>
): Promise<couchbase.GetResult> => {
  const coll = bucket.defaultCollection();
  await coll.upsert(key, value);

  return coll.get(key);
};
it("should connect and query using enterprise image", async () => {
  const bucketDefinition = new BucketDefinition("mybucket");
  const container = await new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE).withBucket(bucketDefinition);

  startedTestContainer = await container.start();

  cluster = new couchbase.Cluster(startedTestContainer.getConnectionString(), {
    username: startedTestContainer.getUsername(),
    password: startedTestContainer.getPassword(),
  });

  const bucket = cluster.bucket(bucketDefinition.getName());
  const result = await upsertAndGet(bucket, "testdoc", { foo: "bar" });

  expect(result.content).toEqual({ foo: "bar" });
});