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.

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);

Hierarchy

  • BaseStore<string, Uint8Array>
    • MongoDBStore

Constructors

Properties

collection: Collection<Document>
namespace?: string
primaryKey: string = "_id"
yieldKeysScanBatchSize: number = 1000

Methods

  • Deletes multiple keys from the MongoDB database.

    Parameters

    • keys: string[]

      Array of keys to be deleted.

    Returns Promise<void>

    Promise that resolves when all keys have been deleted.

  • Gets multiple keys from the MongoDB database.

    Parameters

    • keys: string[]

      Array of keys to be retrieved.

    Returns Promise<(undefined | Uint8Array)[]>

    An array of retrieved values.

  • Sets multiple keys in the MongoDB database.

    Parameters

    • keyValuePairs: [string, Uint8Array][]

      Array of key-value pairs to be set.

    Returns Promise<void>

    Promise that resolves when all keys have been set.

  • Returns Serialized

  • Yields keys from the MongoDB database.

    Parameters

    • Optionalprefix: string

      Optional prefix to filter the keys. A wildcard (*) is always appended to the end.

    Returns AsyncGenerator<string, any, unknown>

    An AsyncGenerator that yields keys from the MongoDB database.