Use this file to discover all available pages before exploring further.
Couchbase is an award-winning distributed NoSQL cloud database that delivers unmatched versatility, performance, scalability, and financial value for all of your cloud, mobile, AI, and edge computing applications.This guide shows how to use load documents from couchbase database.
For more details on connecting to a Couchbase cluster, please check the Node.js SDK documentation.For help with querying for documents using SQL++ (SQL for JSON), please check the documentation.
import { CouchbaseDocumentLoader } from "@langchain/community/document_loaders/web/couchbase";import { Cluster } from "couchbase";const connectionString = "couchbase://localhost"; // valid couchbase connection stringconst dbUsername = "Administrator"; // valid database user with read access to the bucket being queriedconst dbPassword = "Password"; // password for the database user// query is a valid SQL++ queryconst query = ` SELECT h.* FROM \`travel-sample\`.inventory.hotel h WHERE h.country = 'United States' LIMIT 1`;
const loader = new CouchbaseDocumentLoader( couchbaseClient, // The connected couchbase cluster client query // A valid SQL++ query which will return the required data);
You can fetch the documents by calling the load method of the loader. It will return a list with all the documents. If you want to avoid this blocking call, you can call lazy_load method that returns an Iterator.
// using load methoddocs = await loader.load();console.log(docs);
// using lazy_loadfor await (const doc of this.lazyLoad()) { console.log(doc); break; // break based on required condition}
The fields that are part of the Document content can be specified using the pageContentFields parameter.
The metadata fields for the Document can be specified using the metadataFields parameter.