import { Document, Model } from 'mongoose'; /** * DocumentMerger * * Provides a utility to merge references within documents of a MongoDB collection by replacing * all occurrences of an old identifier with a new identifier in specified fields. * * This class handles both single string references and arrays of references, * ensuring unique values after the merge. * * @template T - Type of Mongoose Document * @template Field - Keys of T excluding standard Document properties, representing the fields to update */ export declare class DocumentMerger> { private readonly logger; private readonly model; private readonly oldId; private readonly newId; private readonly fields; /** * Initializes the DocumentMerger with the collection model, IDs to merge, and target fields. * * @param model - Mongoose model representing the target collection * @param oldId - Identifier to be replaced in documents * @param newId - Identifier to replace oldId with * @param fields - List of document fields where replacements should occur */ constructor(model: Model, oldId: string, newId: string, ...fields: Field[]); /** * Executes the merge operation over all documents in the collection. * * Iterates asynchronously through each document using a cursor to avoid loading all documents at once. * For each document: * - Optionally applies a transformation function before merging. * - Replaces occurrences of oldId with newId in each specified field. * - If the field is a string matching oldId, it is replaced directly. * - If the field is an array, each occurrence of oldId is replaced with newId, * and duplicates are removed to maintain uniqueness. * - Saves the updated document without modifying timestamp fields. * * This approach ensures memory efficiency and consistency during the merge process. * * @param transform - Optional callback to modify each document before merging fields * @returns Promise resolving when all documents have been processed and saved */ merge(transform?: (item: Omit) => Omit): Promise; }