Class that extends the BaseStore class to interact with a MongoDB database. It provides methods for getting, setting, and deleting data, as well as yielding keys from the database.
class MongoDBStoreBaseStore<string, Uint8Array>A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.
Deletes multiple keys from the MongoDB database.
Gets multiple keys from the MongoDB database.
Sets multiple keys in the MongoDB database.
Yields keys from the MongoDB database.
The name of the serializable. Override to provide an alias or to preserve the serialized module name in minified environments.
Implemented as a static method to support loading logic.
const client = new MongoClient(process.env.MONGODB_ATLAS_URI);
const collection = client.db("dbName").collection("collectionName");
const store = new MongoDBStore({
collection,
});
const docs = [
[uuidv4(), "Dogs are tough."],
[uuidv4(), "Cats are tough."],
];
const encoder = new TextEncoder();
const docsAsKVPairs: Array<[string, Uint8Array]> = docs.map(
(doc) => [doc[0], encoder.encode(doc[1])]
);
await store.mset(docsAsKVPairs);