UNPKG

afridho-mongodb

Version:

A simple MongoDB client wrapper for easy database operations

83 lines (82 loc) 3.16 kB
import { Document } from "mongodb"; /** * Class representing a MongoDB client for a specific collection. */ declare class ClientDB { private client; private collectionName; private collection; /** * Creates an instance of ClientDB. * @param {string} collectionName - The name of the collection to interact with. */ constructor(collectionName: string); /** * Connects to the MongoDB database and initializes the collection. * @returns {Promise<void>} */ connect(): Promise<void>; /** * Reads a document from the collection based on the provided query. * @param {Document} query - The query to find the document. * @returns {Promise<Document|null>} The found document or null if not found. */ read(query: Document): Promise<Document | null>; /** * Reads all documents from the collection. * @returns {Promise<Document[]>} An array of all documents in the collection. */ readAll(): Promise<Document[]>; /** * Inserts a new document into the collection. * @param {Document} data - The data to insert. * @returns {Promise<Document>} The result of the insert operation. */ insert(data: Document): Promise<Document>; /** * Inserts multiple documents into the collection. * @param {Document[]} data - The data to insert. * @returns {Promise<Document>} The result of the insert operation. */ insertMany(data: Document[]): Promise<Document>; /** * Updates a document in the collection based on the provided query. * @param {Document} query - The query to find the document to update. * @param {Document} data - The data to update. * @returns {Promise<Document>} The result of the update operation. */ update(query: Document, data: Document): Promise<Document>; /** * Deletes a document from the collection based on the provided query. * @param {Document} query - The query to find the document to delete. * @returns {Promise<Document>} The result of the delete operation. */ delete(query: Document): Promise<Document>; /** * Deletes multiple documents from the collection based on the provided query. * @param {Document} query - The query to find the documents to delete. * @returns {Promise<Document>} The result of the delete operation. */ deleteMany(query: Document): Promise<Document>; /** * Finds multiple documents in the collection based on the provided query. * @param {Document} query - The query to find the documents. * @returns {Promise<Document[]>} An array of found documents. */ find(query: Document): Promise<Document[]>; /** * Gets the storage statistics for the collection. * @returns {Promise<{storageSize: number, size: number, count: number}>} The storage statistics including storageSize. */ getStorageStats(): Promise<{ storageSize: number; size: number; count: number; }>; /** * Closes the MongoDB connection. * @returns {Promise<void>} */ close(): Promise<void>; } export default ClientDB;