@resolveio/server-lib 20.4.60 → 20.4.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/mongo.manager.ts"],"names":["simpl_schema_1","require","mongodb_1","index_1","user_collection_1","common_1","log_collection_1","NodeCache","crypto","scmp","monitor_manager_1","os_1","numCPUs","cpus","length","v8","async_1","sift_1","MongoManager","serverConfig","this","_collections","_cacheMap","_operationInProgress","Map","_heapSize","getHeapStatistics","_serverCollections","_serverConfig","_isWorkersEnabled","_isWorkerInstance","_nodeCache","stdTTL","checkperiod","process","env","IS_WORKERS_ENABLED","IS_WORKER_INSTANCE","setCacheLimit","initServerCollections","setupChangeStream","prototype","_heapLimit","ResolveIOServer","getMainDB","listCollections","toArray","collections","_a","sent","getServerCollections","registerCollection","collection","_this","collectionOptions","timeseries","timeField","some","a","name","collectionName","type","dropCollection","then","createCollection","push","find","delay","ms","Promise","resolve","setTimeout","filter","options","cacheKey","generateCacheKey","undefined","result","getFromCache","has","get","promise","operation","executeFind","set","invalidatedDuringExecution","finally","delete","monitor","MonitorMongo","JSON","stringify","finish","addToCache","findOne","executeFindOne","aggregate","pipeline","__spreadArray","__read","flatMap","stage","$lookup","from","executeAggregate","countDocuments","executeCountDocuments","functionName","args","keyString","createHash","update","digest","cachedData","parse","dateReviver","error","del","data","getBinarySize","nodeCacheSize","getStats","vsize","deleteCount","keys","keys_1","__values","keys_1_1","next","done","key","value","console","log","invalidateQueryCache","collectionCacheMap","includes","collectionCacheMap_1","collectionCacheMap_1_1","cacheMap","changeStream","watch","$match","$and","ns.coll","$nin","$not","on","change","__awaiter","coll","err","Date","close","MongoManagerModel","exports","versionOptions","collection_main","collection_version","MongoManagerUserCollection","MongoManagerCollection","useVersionCollection","useVersions","versionSchema","deepCopy","schema","_id","blackbox","useReportBuilder","reportBuilderLookupTables","timestamps","createLogs","checkSchema","createIndex","_id._id","_id.__v","versionCollection","schemaCopy","interval","simplschema","rbSchema","useRB","default","buildRbLookups","buildRbSchema","setInterval","getMainServer","getMongoManager","clearInterval","extractIndexNameFromError","errorMessage","matches","match","skipCache","reject","monitor_1","res","aggregateCount","aggregateCursor","cursor","ev","aggregateStream","streamOptions","stream","bulkWrite","operations","bypassLogs","bypassCheckSchema","bulkOps","logs","modifiedIds","Set","additionalFilters","fieldNamesSet","opIndex","op","opType","Object","doc","document","objectIdHexString","__v","date","createdAt","updatedAt","validation","newContext","validate","Error","concat","validationErrors","insertOne","id_document","payload","method","id_user","user","messageId","route","add","$set","$inc","upsert","$setOnInsert","modifier","replacement","isSingle","extractFieldNames","isUpdateMany","insertMany","isDeleteMany","combinedFilter","$or","map","item","projection_1","forEach","field","projection","docs","_h","docs_1","docs_1_1","e_4","additionalFilters_1","additionalFilters_1_1","mainResult","size","modifiedIdsArray","Array","$in","$addFields","$project","$merge","into","whenMatched","whenNotMatched","$sort","$group","$push","docsToDelete","$slice","$size","$unwind","$replaceRoot","newRoot","oldVersions","deleteMany","expandedLogs","logs_1","logs_1_1","e_6","_b","_c","Logs","ordered","err_1","prefix","startsWith","isArray","subFilter","fullPath","estimatedDocumentCount","monitor_2","err_2","create","f_docs","fieldOrSpec","indexes","existingIndexes","index","indexQueue","action","specs","err_3","createIndexes","indexSpecs","existingIndexes_1","indexesToCreate","indexSpec","existingIndex","err_4","i","versionDoc","replaceOne","$lt","acknowledged","deletedCount","deleteOne","monitor_3","findOneAndDelete","returnVal","monitor_4","distinct","drop","dropIndex","indexName","dropIndexes","monitor_5","findById","id","findCount","count","findCursor","removeAllListeners","findStream","monitor_6","findOneAndReplace","getMethodManager","callMethodInternal","call","findOneAndUpdate","indexExists","bypassMonitor","validationResults","validDocs","idx","hasOwnProperty","monitor_7","listIndexes","rename","newName","monitor_8","modifiedCount","prevDoc","docId","docVersion","updatedDoc_1","getMongoMergeUpdatedDoc","monitor_9","monitor_10","returnDocument","monitor_11","monitor_12","updateMany","bypassVersions","$unset","objectContainsPropertyDeep","updateOne","monitor_13","monitor_14","monitor_15","ok","monitor_16","watchCollection","queue","task","callback","dbCollection","apply","code","err_5","message","existingIndexName","innerError_1","_super","__extends","authenticate","password","attemptsInterval","Math","pow","attempts","calculatedInterval","last","now","getTime","Users","salt","pbkdf2","iterations","keylen","digestAlgorithm","hashBuffer","Buffer","hash","serializeUser","cb","username","deserializeUser","setPassword","randomBytes","saltBuffer","toString","pbkdf2Promisified","hashRaw","services","rej","changePassword","oldPassword","newPassword","authUser","register","email","resetAttempts","ObjectId","toHexString","saltlen","obj","prop"],"mappings":"yxFAAAA,gB,yMAAAC,QAAA,cAAA,GACAC,UAAAD,QAAA,SAAA,EAEAE,QAAAF,QAAA,UAAA,EACAG,kBAAAH,QAAA,gCAAA,EACAI,SAAAJ,QAAA,gBAAA,EAEAK,iBAAAL,QAAA,+BAAA,EACAM,UAAAN,QAAA,YAAA,EACMO,OAASP,QAAQ,QAAQ,EACzBQ,KAAOR,QAAQ,MAAM,EAC3BS,kBAAAT,QAAA,mBAAA,EAEAU,KAAAV,QAAA,IAAA,EACMW,SAAU,EAAAD,KAAAE,MAAI,EAAGC,OACjBC,GAAKd,QAAQ,IAAI,EACvBe,QAAAf,QAAA,OAAA,EACAgB,OAAAhB,QAAA,MAAA,EAqGAiB,aAAA,WAYC,SAAAA,aAAYC,GAXJC,KAAAC,aAA6D,GAE7DD,KAAAE,UAAsD,GACtDF,KAAAG,qBAAoG,IAAIC,IACxGJ,KAAAK,UAAYV,GAAGW,kBAAiB,EAAKd,QAErCQ,KAAAO,mBAAiF,GACjFP,KAAAQ,cAAgB,KAChBR,KAAAS,kBAAoB,CAAA,EACpBT,KAAAU,kBAAoB,CAAA,EAG3BV,KAAKQ,cAAgBT,EACrBC,KAAKW,WAAa,IAAIxB,UAAU,CAAEyB,OAAQ,EAAGC,YAAa,CAAC,CAAE,EAE7Db,KAAKS,kBAAuD,SAAnCK,QAAQC,IAAIC,mBACrChB,KAAKU,kBAAuD,SAAn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AAQ,CACpG,CAEA,SAASqC,kBAAkB1B,EAAUU,EAAM/U,GAC1C,OAAO,IAAIJ,QAAQ,SAACC,EAAS4H,GAAW,OAAAuN,OAAOX,EAAUU,EAAM/U,EAAS,SAAC8E,EAAKkR,GAAY,OAAClR,EAAM2C,EAAO3C,CAAG,EAAIjF,EAAQmW,CAAO,CAApC,CAAsC,CAAxF,CAAyF,CAClI,CAEA,SAASJ,YAAYgB,GACpB,OAAO,IAAIhX,QAAQ,SAACC,EAAS4H,GAAW,OAAA1L,OAAO6Z,YAAYgB,EAAS,SAAC9R,EAAK+Q,GAAe,OAAC/Q,EAAM2C,EAAO3C,CAAG,EAAIjF,EAAQgW,CAAU,CAAvC,CAAyC,CAA1F,CAA2F,CACpI,CAEA,SAAS7C,2BAA2B6D,EAAaC,GAChD,IAAI3T,EAAO6F,OAAO7F,KAAK0T,CAAG,EAE1B,GAAI1T,EAAKnE,KAAK,SAAAC,GAAK,OAAAA,IAAM6X,CAAN,CAAU,EAC5B,MAAO,CAAA,EAGR,IAAK,IAAIrH,EAAI,EAAGA,EAAItM,EAAK9G,OAAQoT,CAAC,GAAI,CACrC,IAAIhM,EAAMN,EAAKsM,GACf,GAAIoH,EAAIpT,IAA4B,UAApB,OAAOoT,EAAIpT,IAAqBuP,2BAA2B6D,EAAIpT,GAAMqT,CAAI,EACxF,MAAO,CAAA,C,CAIT,MAAO,CAAA,CACR,CA3Ma5R,QAAAI,2BAAAA,2BA2KbJ,QAAAiE,kBAAAA","file":"mongo.manager.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { AggregateOptions, AggregationCursor, BulkWriteOptions, ChangeStream, ChangeStreamOptions, CommandOperationOptions, CountDocumentsOptions, CreateCollectionOptions, CreateIndexesOptions, CursorStreamOptions, DeleteOptions, Filter, FindCursor, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, FindOptions, IndexDescription, IndexInformationOptions, InsertOneOptions, ListIndexesCursor, ListIndexesOptions, ObjectId, RenameOptions, ReplaceOptions, UpdateOptions, OptionalId, Collection, CollectionInfo, OptionalUnlessRequiredId, AnyBulkWriteOperation, BulkWriteResult, DbStatsOptions, ChangeStreamDocument } from 'mongodb';\nimport { LookupTables } from '../models/report-builder.model';\nimport { ResolveIOServer } from '../index';\nimport { Users } from '../collections/user.collection';\nimport { buildRbLookups, buildRbSchema, dateReviver, deepCopy, getBinarySize, getMongoMergeUpdatedDoc } from '../util/common';\nimport { UserModel } from '../models/user.model';\nimport { Logs } from '../collections/log.collection';\nimport * as NodeCache from 'node-cache';\nconst crypto = require('crypto');\nconst scmp = require('scmp');\nimport { MonitorMongo } from './monitor.manager';\nimport { CollectionDocument, Document } from '../models/collection-document.model';\nimport { cpus } from 'os';\nconst numCPUs = cpus().length;\nconst v8 = require('v8');\nimport async from 'async';\nimport sift from 'sift';\n\ninterface MongoQueueModel {\n\t_id: number,\n\tname_collection: string;\n\tlookup_collections: string[];\n\tname_function: string;\n\tdata_function: any[];\n\tname_function_addt: string;\n\tdata_function_addt: any[];\n\tcbs: Function[];\n\tcbs_next: Function[];\n\trunning: boolean;\n\tcacheId: number;\n\tinvalidateFlag: boolean;\n\tinvalidateCount: number;\n}\n\n// export declare interface MongoManagerFilterOperators<T> extends Document {\nexport declare interface MongoManagerFilterParamaterOperators<P> {\n\t$eq?: P;\n $gt?: P;\n $gte?: P;\n $in?: P extends Array<any> ? P : P[];\n $lt?: P;\n $lte?: P;\n $ne?: P;\n $nin?: P extends Array<any> ? P : P[];\n $not?: P extends string ? MongoManagerFilterParamaterOperators<P> | RegExpConstructor : MongoManagerFilterParamaterOperators<P>;\n $exists?: boolean;\n $expr?: any[]\n $regex?: P extends string ? RegExpConstructor | string : never;\n $options?: P extends string ? string : never;\n $geoIntersects?: {\n $geometry: Document;\n };\n $geoWithin?: Document;\n $near?: Document;\n $nearSphere?: Document;\n $maxDistance?: number;\n $all?: any[];\n $elemMatch?: Document;\n $size?: P extends any[] ? number : never;\n}\n\nexport declare interface MongoManagerFilterOperators<T> extends Document { //TODO: Remove extends document when I get answer on S.O.\n $and?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;\n $nor?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;\n $or?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;\n $text?: {\n $search: string;\n $language?: string;\n $caseSensitive?: boolean;\n $diacriticSensitive?: boolean;\n };\n $where?: string | ((this: T) => boolean);\n $comment?: string | Document;\n}\n\n// function isDotStringRegExp(obj: Object, dotKey: string): boolean {\n// \tlet keyData = dotKey.split('.');\n// \tlet objData = obj;\n\t\n// \tfor (let i = 0; i < keyData.length; i++) {\n// \t\tlet key = keyData[i];\n// \t\tif (objData.hasOwnProperty(key)) {\n// \t\t\tobjData = objData[key];\n\t\t\t\n// \t\t\tif (i === keyData.length - 1) {\n// \t\t\t\treturn true;\n// \t\t\t}\n// \t\t}\n// \t\telse {\n// \t\t\treturn false;\n// \t\t}\n// \t}\n// }\n\n// export declare type MongoManagerDotStringFilter<T> = {\n// \t[key: string]: (isDotStringRegExp(T, key) ? any : never);\n// };\n\nexport declare type MongoManagerFilter<T> = {\n\t[P in keyof T]?: T[P] | MongoManagerFilterParamaterOperators<T[P]>;\n};\n\nexport declare type MongoManagerUnsetFilter<T> = {\n\t[P in keyof T]?: number | boolean;\n};\n\nexport declare type MongoManagerIncFilter<T> = {\n\t[P in keyof T]?: number;\n};\n\nexport declare type MongoManagerUpdateFilter<T> = {\n $inc?: MongoManagerIncFilter<T> | Document;\n $set?: MongoManagerFilter<T> | Document;\n $setOnInsert?: MongoManagerFilter<T> | Document;\n $unset?: MongoManagerUnsetFilter<T> | Document;\n};\n\nexport class MongoManager {\n\tprivate _collections: MongoManagerCollection<CollectionDocument>[] = [];\n\tprivate _nodeCache;\n\tprivate _cacheMap: { collections: string[], key: string }[] = [];\n\tprivate _operationInProgress: Map<string, { promise: Promise<any>, invalidatedDuringExecution: boolean }> = new Map();\n\tprivate _heapSize = v8.getHeapStatistics() / numCPUs;\n\tprivate _heapLimit: number;\n\tprivate _serverCollections: (CollectionInfo | Pick<CollectionInfo, 'name' | 'type'>)[] = [];\n\tprivate _serverConfig = null;\n\tprivate _isWorkersEnabled = false;\n\tprivate _isWorkerInstance = false;\n\n\tconstructor(serverConfig) {\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._nodeCache = new NodeCache({ stdTTL: 0, checkperiod: 0 });\n\n\t\tthis._isWorkersEnabled = process.env.IS_WORKERS_ENABLED === 'true';\n\t\tthis._isWorkerInstance = process.env.IS_WORKER_INSTANCE === 'true';\n\t\tthis.setCacheLimit();\n\n\t\tthis.initServerCollections();\n\n\t\tif (this._isWorkersEnabled && this._isWorkerInstance) {\n\t\t\tthis.setupChangeStream();\n\t\t}\n\t}\n\n\tprivate setCacheLimit() {\n\t\tif (this._isWorkersEnabled) {\n\t\t\tthis._heapLimit = this._isWorkerInstance ? this._heapSize * 0.8 : this._heapSize * 0.4;\n\t\t}\n\t\telse {\n\t\t\tthis._heapLimit = this._heapSize * 0.3;\n\t\t}\n\t}\n\n\tasync initServerCollections() {\n\t\tlet collections = await ResolveIOServer.getMainDB().listCollections().toArray();\n\t\tthis._serverCollections = collections;\n\t}\n\n\tgetServerCollections() {\n\t\treturn this._serverCollections;\n\t}\n\n\tregisterCollection(collection: MongoManagerCollection<CollectionDocument>) {\n\t\tif (\n\t\t\tcollection.collectionOptions &&\n\t\t\tcollection.collectionOptions.timeseries &&\n\t\t\tcollection.collectionOptions.timeseries.timeField &&\n\t\t\tthis._serverCollections.some(a => a.name === collection.collectionName && a.type === 'collection')\n\t\t) {\n\t\t\tResolveIOServer.getMainDB()\n\t\t\t\t.dropCollection(collection.collectionName)\n\t\t\t\t.then(() => {\n\t\t\t\t\tthis.createCollection(collection);\n\t\t\t\t});\n\t\t}\n\n\t\tthis._collections.push(collection);\n\t}\n\n\tcreateCollection(collection: MongoManagerCollection<CollectionDocument>) {\n\t\tResolveIOServer.getMainDB().createCollection<CollectionDocument>(collection.collectionName, collection.collectionOptions);\n\t}\n\n\tcollections() {\n\t\treturn this._collections;\n\t}\n\n\tcollection(collectionName: string): MongoManagerCollection<CollectionDocument> | MongoManagerUserCollection<CollectionDocument> {\n\t\treturn this._collections.find(a => a.collectionName === collectionName);\n\t}\n\n\tprivate async delay(ms: number) {\n\t\treturn new Promise(resolve => setTimeout(resolve, ms));\n\t}\n\n\tpublic async find<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {},\n\t\toptions?: FindOptions<T>\n\t): Promise<T[]> {\n\t\tconst cacheKey = this.generateCacheKey([collectionName], 'find', [filter, options]);\n\t\tlet result = this.getFromCache(cacheKey);\n\t\tif (result !== undefined) {\n\t\t\treturn result;\n\t\t}\n\n\t\tif (this._operationInProgress.has(cacheKey)) {\n\t\t\treturn this._operationInProgress.get(cacheKey).promise;\n\t\t}\n\n\t\tconst operation = this.executeFind<T>(collectionName, filter, options, cacheKey);\n\t\tthis._operationInProgress.set(cacheKey, { promise: operation, invalidatedDuringExecution: false });\n\n\t\toperation.finally(() => this._operationInProgress.delete(cacheKey));\n\n\t\treturn operation;\n\t}\n\n\tprivate async executeFind<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>,\n\t\toptions: FindOptions<T> | undefined,\n\t\tcacheKey: string\n\t): Promise<T[]> {\n\t\tlet result;\n\t\tconst collection = ResolveIOServer.getMainDB().collection<T>(collectionName);\n\n\t\tconst monitor = new MonitorMongo('find', collectionName, JSON.stringify([filter, options]));\n\t\tresult = await collection.find(<any>filter, options).toArray();\n\t\tmonitor.finish();\n\t\n\t\tif (!this._operationInProgress.get(cacheKey).invalidatedDuringExecution) {\n\t\t\tthis.addToCache([collectionName], cacheKey, result);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t// FindOne Operation\n\tpublic async findOne<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> | MongoManagerFilterOperators<T> = {},\n\t\toptions?: FindOptions<T>\n\t): Promise<T> {\n\t\tconst cacheKey = this.generateCacheKey([collectionName], 'findOne', [filter, options]);\n\t\tlet result = this.getFromCache(cacheKey);\n\t\tif (result !== undefined) {\n\t\t\treturn result;\n\t\t}\n\n\t\tif (this._operationInProgress.has(cacheKey)) {\n\t\t\treturn this._operationInProgress.get(cacheKey).promise;\n\t\t}\n\n\t\tconst operation = this.executeFindOne<T>(collectionName, filter, options, cacheKey);\n\t\tthis._operationInProgress.set(cacheKey, { promise: operation, invalidatedDuringExecution: false });\n\n\t\toperation.finally(() => this._operationInProgress.delete(cacheKey));\n\n\t\treturn operation;\n\t}\n\n\tprivate async executeFindOne<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> | MongoManagerFilterOperators<T>,\n\t\toptions: FindOptions<T> | undefined,\n\t\tcacheKey: string\n\t): Promise<T> {\n\t\tlet result;\n\t\tconst collection = ResolveIOServer.getMainDB().collection<T>(collectionName);\n\n\t\tconst monitor = new MonitorMongo('findOne', collectionName, JSON.stringify([filter, options]));\n\t\tresult = await collection.findOne(<any>filter, options);\n\t\tmonitor.finish();\n\t\n\t\tif (!this._operationInProgress.get(cacheKey).invalidatedDuringExecution) {\n\t\t\tthis.addToCache([collectionName], cacheKey, result);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t// Aggregate Operation\n\tpublic async aggregate<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tpipeline: any[],\n\t\toptions?: AggregateOptions\n\t): Promise<any[]> {\n\t\tconst collections = [collectionName, ...pipeline.flatMap(stage => stage.$lookup?.from ? [stage.$lookup.from] : [])];\n\t\tconst cacheKey = this.generateCacheKey(collections, 'aggregate', [pipeline, options]);\n\t\tlet result = this.getFromCache(cacheKey);\n\t\tif (result !== undefined) {\n\t\t\treturn result;\n\t\t}\n\n\t\tif (this._operationInProgress.has(cacheKey)) {\n\t\t\treturn this._operationInProgress.get(cacheKey).promise;\n\t\t}\n\n\t\tconst operation = this.executeAggregate<T>(collectionName, pipeline, options, cacheKey, collections);\n\t\tthis._operationInProgress.set(cacheKey, { promise: operation, invalidatedDuringExecution: false });\n\n\t\toperation.finally(() => this._operationInProgress.delete(cacheKey));\n\n\t\treturn operation;\n\t}\n\n\tprivate async executeAggregate<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tpipeline: any[],\n\t\toptions: AggregateOptions | undefined,\n\t\tcacheKey: string,\n\t\tcollections: string[]\n\t): Promise<any[]> {\n\t\tlet result;\n\t\tconst collection = ResolveIOServer.getMainDB().collection<T>(collectionName);\n\n\t\tconst monitor = new MonitorMongo('aggregate', collectionName, JSON.stringify([pipeline, options]));\n\t\tresult = await collection.aggregate(pipeline, options).toArray();\n\t\tmonitor.finish();\n\n\t\tif (!this._operationInProgress.get(cacheKey).invalidatedDuringExecution) {\n\t\t\tthis.addToCache(collections, cacheKey, result);\n\t\t}\n\t\t\n\t\treturn result;\n\t}\n\n\tpublic async countDocuments<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> | MongoManagerFilterOperators<T> = {},\n\t\toptions?: CountDocumentsOptions\n\t): Promise<number> {\n\t\tconst cacheKey = this.generateCacheKey([collectionName], 'countDocuments', [filter, options]);\n\t\tlet result = this.getFromCache(cacheKey);\n\t\tif (result !== undefined) {\n\t\t\treturn result;\n\t\t}\n\n\t\tif (this._operationInProgress.has(cacheKey)) {\n\t\t\treturn this._operationInProgress.get(cacheKey).promise;\n\t\t}\n\n\t\tconst operation = this.executeCountDocuments<T>(collectionName, filter, options, cacheKey);\n\t\tthis._operationInProgress.set(cacheKey, { promise: operation, invalidatedDuringExecution: false });\n\n\t\toperation.finally(() => this._operationInProgress.delete(cacheKey));\n\n\t\treturn operation;\n\t}\n\n\tprivate async executeCountDocuments<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> | MongoManagerFilterOperators<T>,\n\t\toptions: CountDocumentsOptions,\n\t\tcacheKey: string\n\t): Promise<number> {\n\t\tlet result;\n\t\tconst collection = ResolveIOServer.getMainDB().collection<T>(collectionName);\n\n\t\tconst monitor = new MonitorMongo('countDocuments', collectionName, JSON.stringify([filter, options]));\n\t\tresult = await collection.countDocuments(<any>filter, options);\n\t\tmonitor.finish();\n\t\n\t\tif (!this._operationInProgress.get(cacheKey).invalidatedDuringExecution) {\n\t\t\tthis.addToCache([collectionName], cacheKey, result);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t// Cache and Invalidation Setup\n\tprivate generateCacheKey(collections: string[], functionName: string, args: any[]): string {\n\t\tconst keyString = JSON.stringify({ collections, functionName, args });\n\t\treturn crypto.createHash('sha256').update(keyString).digest('hex');\n\t}\n\n\tprivate getFromCache(cacheKey: string): any | undefined {\n\t\ttry {\n\t\t\tconst cachedData = this._nodeCache.get(cacheKey);\n\t\t\tif (cachedData) {\n\t\t\t\treturn JSON.parse(cachedData, dateReviver);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis._nodeCache.del(cacheKey);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate addToCache(collections: string[], cacheKey: string, data: any) {\n\t\tif (getBinarySize(JSON.stringify(data)) < 1000000) {\n\t\t\tlet nodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\tlet deleteCount = 0;\n\t\t\t\tconst keys = this._nodeCache.keys();\n\n\t\t\t\tfor (const key of keys) {\n\t\t\t\t\tthis._nodeCache.del(key);\n\t\t\t\t\tdeleteCount += 1;\n\n\t\t\t\t\tnodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\t\t\tif (nodeCacheSize < this._heapLimit * 0.75) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconsole.log('Query Cache: ' + 'Too Big, - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);\n\t\t\t}\n\t\t\t\n\t\t\tthis._nodeCache.set(cacheKey, JSON.stringify(data));\n\t\t\tthis._cacheMap.push({ collections, key: cacheKey });\n\t\t}\n\t}\n\n\tpublic invalidateQueryCache(collection: string) {\n\t\tconst collectionCacheMap = this._cacheMap.filter(a => a.collections.includes(collection));\n\n\t\tfor (const cacheMap of collectionCacheMap) {\n\t\t\tthis._nodeCache.del(cacheMap.key);\n\t\t\t\n\t\t\tif (this._operationInProgress.has(cacheMap.key)) {\n\t\t\t\tthis._operationInProgress.get(cacheMap.key).invalidatedDuringExecution = true;\n\t\t\t}\n\t\t}\n\n\t\tthis._cacheMap = this._cacheMap.filter(a => !a.collections.includes(collection));\n\t}\n\n\tprivate setupChangeStream() {\n\t\tconst db = ResolveIOServer.getMainDB();\n\n\t\tconst pipeline = [\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t$and: [\n\t\t\t\t\t\t{'ns.coll': { $nin: ['logs', 'log-method-latencies', 'log-subscriptions'] }},\n\t\t\t\t\t\t{'ns.coll': { $not: /.*\\.versions$/ }},\n\t\t\t\t\t\t{'ns.coll': { $not: /^monitor-/ }},\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t\tconst changeStream = db.watch(pipeline);\n\n\t\tchangeStream.on('change', async (change: ChangeStreamDocument) => {\n\t\t\tif (change['ns'] && change['ns'].coll) {\n\t\t\t\tconst collectionName = change['ns'].coll;\n\t\t\t\tif (this.collection(collectionName)) {\n\t\t\t\t\tthis.invalidateQueryCache(collectionName);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tchangeStream.on('error', err => {\n\t\t\tconsole.log(new Date(), 'Mongo change stream error. Restart...');\n\t\t\tchangeStream.close();\n\t\t\tsetTimeout(() => this.setupChangeStream(), 5000);\n\t\t});\n\n\t\tchangeStream.on('close', () => {\n\t\t\tconsole.log(new Date(), 'Mongo change stream closed. Restarting...');\n\t\t\tsetTimeout(() => this.setupChangeStream(), 5000);\n\t\t});\n\t}\n}\n\nexport class MongoManagerModel<T extends CollectionDocument> {\n\tcollection_main: MongoManagerCollection<T> | MongoManagerUserCollection<T> = null;\n\tcollection_version: MongoManagerCollection<T> | MongoManagerUserCollection<T> = null;\n\n\tconstructor(options: MongoManagerCollectionOptions) {\n\t\tif (options.collectionName === 'users') {\n\t\t\tthis.collection_main = new MongoManagerUserCollection<T>(options);\n\t\t}\n\t\telse {\n\t\t\tthis.collection_main = new MongoManagerCollection<T>(options);\n\t\t}\n\n\t\tif (options.useVersionCollection) {\n\t\t\tthis.collection_main.useVersions = true;\n\t\t\t\n\t\t\tlet versionSchema = deepCopy(options.schema);\n\t\t\tversionSchema._id.type = 'Object';\n\t\t\tversionSchema._id.blackbox = true;\n\n\t\t\tlet versionOptions: MongoManagerCollectionOptions = {\n\t\t\t\tcollectionName: options.collectionName + '.versions',\n\t\t\t\tschema: versionSchema,\n\t\t\t\tuseVersionCollection: false,\n\t\t\t\tuseReportBuilder: false,\n\t\t\t\treportBuilderLookupTables: [],\n\t\t\t\ttimestamps: true,\n\t\t\t\tcreateLogs: false,\n\t\t\t\tcheckSchema: false,\n\t\t\t\tcollectionOptions: null\n\t\t\t};\n\n\t\t\tif (options.collectionName === 'users') {\t\n\t\t\t\tthis.collection_version = new MongoManagerUserCollection<T>(versionOptions);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.collection_version = new MongoManagerCollection<T>(versionOptions);\n\t\t\t}\n\n\t\t\tthis.collection_version.createIndex({'_id._id': 1, '_id.__v': 1});\n\t\t\tthis.collection_main.versionCollection = options.collectionName + '.versions';\n\t\t}\n\t}\n}\n\nexport interface MongoManagerCollectionOptions {\n\tcollectionName: string;\n\tschema: object;\n\tuseVersionCollection: boolean;\n\tuseReportBuilder: boolean;\n\treportBuilderLookupTables: LookupTables[]\n\ttimestamps: boolean;\n\tcreateLogs: boolean;\n\tcheckSchema: boolean;\n\tcollectionOptions: CreateCollectionOptions;\n}\n\nexport class MongoManagerCollection<T extends CollectionDocument> {\n\tcollectionName = '';\n\tcheckSchema = false;\n\tsimplschema = null;\n\trbSchema = null;\n\ttimestamps = false;\n\tuseVersions = false;\n\tversionCollection = '';\n\tcreateLogs = true;\n\tuseRB = false;\n\tcollectionOptions: CreateCollectionOptions;\n\t\n\tconstructor(options: MongoManagerCollectionOptions) {\n\t\tthis.collectionName = options.collectionName;\n\t\tthis.simplschema = new SimpleSchema(options.schema);\n\t\tthis.timestamps = options.timestamps;\n\t\tthis.createLogs = options.createLogs;\n\t\tthis.checkSchema = options.checkSchema;\n\t\tthis.collectionOptions = options.collectionOptions;\n\n\t\tif (options.useReportBuilder) {\n\t\t\tthis.useRB = true;\n\t\t\tlet schemaCopy = deepCopy(options.schema);\n\t\t\tlet rbSchema = buildRbLookups(options.reportBuilderLookupTables, schemaCopy, []);\n\t\t\tthis.rbSchema = buildRbSchema(rbSchema);\n\t\t}\n\n\t\tlet interval = setInterval(() => {\n\t\t\tif (ResolveIOServer && ResolveIOServer.getMainServer() && ResolveIOServer.getMongoManager() && ResolveIOServer.getMongoManager().getServerCollections().length) {\n\t\t\t\tResolveIOServer.getMongoManager().registerCollection(this);\n\t\t\t\tclearInterval(interval);\n\t\t\t}\n\t\t}, 1);\n\t}\n\n\tprivate static indexQueue = async.queue(async (task, callback) => {\n\t\tconst { action, collection, specs, options } = task;\n\t\tconst dbCollection = ResolveIOServer.getMainDB().collection(collection.collectionName, collection.collectionOptions);\n\t\n\t\tif (!dbCollection) {\n\t\t\treturn callback(new Error(`Collection ${collection.collectionName} not found`));\n\t\t}\n\t\n\t\tlet monitor = new MonitorMongo(action, collection.collectionName, JSON.stringify([specs, options]));\n\t\n\t\ttry {\n\t\t\t// Try creating the index, will auto-skip if already checked in createIndex/createIndexes\n\t\t\tconst result = await dbCollection[action](...specs, options);\n\t\t\tmonitor.finish();\n\t\t\tcallback(null, result);\n\t\t} catch (err) {\n\t\t\t// Handle any specific errors related to index creation\n\t\t\tif (err.code === 85 || err.message.includes('IndexOptionsConflict')) {\n\t\t\t\ttry {\n\t\t\t\t\tconst existingIndexName = collection.extractIndexNameFromError(err.message);\n\t\t\t\t\tif (existingIndexName) {\n\t\t\t\t\t\tawait dbCollection.dropIndex(existingIndexName);\n\t\t\t\t\t\tconst result = await dbCollection[action](...specs, options);\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tcallback(null, result);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} catch (innerError) {\n\t\t\t\t\tcallback(innerError);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmonitor.finish();\n\t\t\tcallback(err);\n\t\t}\n\t}, 1);\n\n // Method to extract index name from error message\n extractIndexNameFromError(errorMessage) {\n\t\tlet regexPattern = /Index already exists with a different name: (\\S+)/;\n\t\tlet matches = errorMessage.match(regexPattern);\n\t\n\t\tif (!matches || matches.length <= 1) {\n\t\t\t// If the first pattern doesn't match, try the second pattern\n\t\t\tregexPattern = /existing index:.*name: \"([^\"]+)\"/;\n\t\t\tmatches = errorMessage.match(regexPattern);\n\t\t}\n\t\n\t\treturn matches && matches.length > 1 ? matches[1] : null;\n\t}\t\n\n\taggregate(pipeline: object[], options?: AggregateOptions, skipCache = false) : Promise<any[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tif (!skipCache) {\n\t\t\t\tResolveIOServer.getMongoManager().aggregate(this.collectionName, pipeline, options).then(res => {\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet monitor = new MonitorMongo('aggregate', this.collectionName, JSON.stringify([pipeline, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).aggregate(pipeline, options).toArray().then(res => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Aggregate', this.collectionName, pipeline, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tasync aggregateCount(pipeline: object[], options?: AggregateOptions) : Promise<number> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('aggregateCount', this.collectionName, JSON.stringify([pipeline, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).aggregate(pipeline, options).toArray().then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res.length);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Aggregate', this.collectionName, pipeline, options, err);\n\t\t\t\treject(0);\n\t\t\t});\n\t\t});\n\t}\n\n\taggregateCursor(pipeline: object[], options?: AggregateOptions): AggregationCursor {\n\t\tlet monitor = new MonitorMongo('aggregateCursor', this.collectionName, JSON.stringify([pipeline, options]));\n\t\tlet cursor = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).aggregate(pipeline, options);\n\t\tcursor.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn cursor;\n\t}\n\n\taggregateStream(pipeline: object[], options?: AggregateOptions, streamOptions?: CursorStreamOptions) {\n\t\tlet monitor = new MonitorMongo('aggregateStream', this.collectionName, JSON.stringify([pipeline, options, streamOptions]));\n\t\tlet stream = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).aggregate(pipeline, options).stream(streamOptions);\n\t\tstream.on('end', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t})\n\t\t.on('error', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t})\n\t\t.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn stream;\n\t}\n\n\t// bulkWrite(operations: AnyBulkWriteOperation<T>[], options: BulkWriteOptions): Promise<BulkWriteResult> {\n\tasync bulkWrite(\n\t\toperations: any[],\n\t\toptions?: BulkWriteOptions,\n\t\tbypassLogs = false,\n\t\tbypassCheckSchema = false\n\t): Promise<BulkWriteResult> {\n\t\tif (!operations.length) {\n\t\t\treturn null;\n\t\t}\n\t\n\t\tconst bulkOps = [];\n\t\tconst logs = [];\n\t\tconst modifiedIds = new Set<string>();\n\t\n\t\tconst additionalFilters = [];\n\t\tconst fieldNamesSet = new Set<string>();\n\t\n\t\t// Prepare bulk operations and collect modified IDs\n\t\tfor (let opIndex = 0; opIndex < operations.length; opIndex++) {\n\t\t\tconst op = operations[opIndex];\n\t\t\tconst opType = Object.keys(op)[0];\n\t\t\tconst doc = op[opType];\n\t\n\t\t\tif (opType === 'insertOne') {\n\t\t\t\t// Handle insertOne\n\t\t\t\tif (!doc.document._id) {\n\t\t\t\t\tdoc.document._id = objectIdHexString();\n\t\t\t\t}\n\t\t\t\tif (this.useVersions && doc.document.__v === undefined) {\n\t\t\t\t\tdoc.document.__v = 0;\n\t\t\t\t}\n\t\t\t\tif (this.timestamps) {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdoc.document.createdAt = doc.document.createdAt || date;\n\t\t\t\t\tdoc.document.updatedAt = doc.document.updatedAt || date;\n\t\t\t\t}\n\t\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\tif (!validation.validate(doc.document)) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Schema validation failed for insertOne: ${JSON.stringify(validation.validationErrors())}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbulkOps.push(op);\n\t\n\t\t\t\t// Collect logs if necessary\n\t\t\t\tif (!bypassLogs && this.createLogs) {\n\t\t\t\t\tlogs.push({\n\t\t\t\t\t\tinsertOne: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: doc.document._id,\n\t\t\t\t\t\t\t\tpayload:\n\t\t\t\t\t\t\t\t\tgetBinarySize(JSON.stringify([op, options])) < 200000\n\t\t\t\t\t\t\t\t\t\t? JSON.stringify([op, options], null, 2)\n\t\t\t\t\t\t\t\t\t\t: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: opType,\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\n\t\t\t\t// Track inserted IDs for versioning\n\t\t\t\tif (this.useVersions) {\n\t\t\t\t\tmodifiedIds.add(doc.document._id);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (opType === 'updateOne' || opType === 'replaceOne') {\n\t\t\t\t// Handle updateOne and replaceOne\n\t\t\t\tif (opType === 'updateOne') {\n\t\t\t\t\tif (!doc.update.$set) doc.update.$set = {};\n\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\tdoc.update.$set.updatedAt = new Date();\n\t\t\t\t\t}\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tif (!doc.update.$inc) doc.update.$inc = {};\n\t\t\t\t\t\tdoc.update.$inc.__v = 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (doc.upsert) {\n\t\t\t\t\t\tif (!doc.update.$setOnInsert) doc.update.$setOnInsert = {};\n\t\t\t\t\t\tif (!doc.update.$setOnInsert._id) doc.update.$setOnInsert._id = objectIdHexString();\n\t\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\t\tdoc.update.$setOnInsert.createdAt = new Date();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\t\tdoc.update.$setOnInsert.__v = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\t\tif (!validation.validate(doc.update, { modifier: true })) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Schema validation failed for updateOne: ${JSON.stringify(validation.validationErrors())}`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (opType === 'replaceOne') {\n\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\tdoc.replacement.updatedAt = new Date();\n\t\t\t\t\t\tif (doc.upsert && !doc.replacement.createdAt) {\n\t\t\t\t\t\t\tdoc.replacement.createdAt = new Date();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tdoc.replacement.__v = doc.replacement.__v !== undefined ? doc.replacement.__v + 1 : 0;\n\t\t\t\t\t}\n\t\t\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\t\tif (!validation.validate(doc.replacement)) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Schema validation failed for replaceOne: ${JSON.stringify(validation.validationErrors())}`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbulkOps.push(op);\n\t\n\t\t\t\t// Collect logs if necessary\n\t\t\t\tif (!bypassLogs && this.createLogs) {\n\t\t\t\t\tlet id_document = '';\n\t\t\t\t\tif (doc.filter && doc.filter._id) {\n\t\t\t\t\t\tid_document = doc.filter._id;\n\t\t\t\t\t\t// Track modified IDs for versioning\n\t\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\t\tmodifiedIds.add(doc.filter._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Collect filters for additional querying\n\t\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: logs.length, isSingle: true });\n\t\t\t\t\t\t// Extract field names from filter\n\t\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tlogs.push({\n\t\t\t\t\t\tinsertOne: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: id_document,\n\t\t\t\t\t\t\t\tpayload:\n\t\t\t\t\t\t\t\t\tgetBinarySize(JSON.stringify([op, options])) < 200000\n\t\t\t\t\t\t\t\t\t\t? JSON.stringify([op, options], null, 2)\n\t\t\t\t\t\t\t\t\t\t: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: opType,\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// Even if not logging, we need to track modified IDs for versioning\n\t\t\t\t\tif (doc.filter && doc.filter._id && this.useVersions) {\n\t\t\t\t\t\tmodifiedIds.add(doc.filter._id);\n\t\t\t\t\t}\n\t\t\t\t\telse if (this.useVersions) {\n\t\t\t\t\t\t// Need to collect filters to fetch _id later\n\t\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: null, isSingle: true });\n\t\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (opType === 'updateMany') {\n\t\t\t\t// Handle updateMany\n\t\t\t\tif (!doc.update.$set) doc.update.$set = {};\n\t\t\t\tif (this.timestamps) {\n\t\t\t\t\tdoc.update.$set.updatedAt = new Date();\n\t\t\t\t}\n\t\t\t\tif (this.useVersions) {\n\t\t\t\t\tif (!doc.update.$inc) doc.update.$inc = {};\n\t\t\t\t\tdoc.update.$inc.__v = 1;\n\t\t\t\t}\n\t\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\tif (!validation.validate(doc.update, { modifier: true })) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Schema validation failed for updateMany: ${JSON.stringify(validation.validationErrors())}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbulkOps.push(op);\n\t\n\t\t\t\t// Collect logs if necessary\n\t\t\t\tif (!bypassLogs && this.createLogs) {\n\t\t\t\t\t// We need to fetch the affected documents to get their _id\n\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: logs.length, isUpdateMany: true });\n\t\t\t\t\t// Extract field names from filter\n\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\n\t\t\t\t\tlogs.push({\n\t\t\t\t\t\tinsertMany: [] // We will populate this after fetching documents\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t// Need to collect filters to fetch _id for versioning\n\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: null, isUpdateMany: true });\n\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (opType === 'deleteOne' || opType === 'deleteMany') {\n\t\t\t\t// Handle deleteOne and deleteMany\n\t\t\t\tbulkOps.push(op);\n\t\n\t\t\t\t// Collect logs if necessary\n\t\t\t\tif (!bypassLogs && this.createLogs) {\n\t\t\t\t\tlet id_document = '';\n\t\t\t\t\tif (doc.filter && doc.filter._id) {\n\t\t\t\t\t\tid_document = doc.filter._id;\n\t\t\t\t\t\t// Track modified IDs for versioning\n\t\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\t\tmodifiedIds.add(doc.filter._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Collect filters for additional querying\n\t\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: logs.length, isDeleteMany: opType === 'deleteMany' });\n\t\t\t\t\t\t// Extract field names from filter\n\t\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tlogs.push({\n\t\t\t\t\t\tinsertOne: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: id_document,\n\t\t\t\t\t\t\t\tpayload:\n\t\t\t\t\t\t\t\t\tgetBinarySize(JSON.stringify([op, options])) < 200000\n\t\t\t\t\t\t\t\t\t\t? JSON.stringify([op, options], null, 2)\n\t\t\t\t\t\t\t\t\t\t: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: opType,\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (this.useVersions) {\n\t\t\t\t\tif (doc.filter && doc.filter._id) {\n\t\t\t\t\t\tmodifiedIds.add(doc.filter._id);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Need to collect filters to fetch _id for versioning\n\t\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: null, isDeleteMany: opType === 'deleteMany' });\n\t\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new Error(`Unsupported operation type: ${opType}`);\n\t\t\t}\n\t\t}\n\t\n\t\ttry {\n\t\t\t// Fetch necessary fields for logs and versioning where required\n\t\t\tif (additionalFilters.length) {\n\t\t\t\t// Combine all filters into one query using $or\n\t\t\t\tconst combinedFilter = {\n\t\t\t\t\t$or: additionalFilters.map(item => item.filter)\n\t\t\t\t};\n\t\n\t\t\t\t// Build the projection object with necessary fields\n\t\t\t\tconst projection: any = { _id: 1 };\n\t\t\t\tfieldNamesSet.forEach(field => {\n\t\t\t\t\tprojection[field] = 1;\n\t\t\t\t});\n\t\n\t\t\t\t// Fetch matching documents with necessary fields\n\t\t\t\tconst cursor = ResolveIOServer.getMainDB()\n\t\t\t\t\t.collection<T>(this.collectionName)\n\t\t\t\t\t.find(combinedFilter, { projection });\n\t\n\t\t\t\tconst docs = await cursor.toArray();\n\t\n\t\t\t\t// Map documents to their filters\n\t\t\t\tfor (const doc of docs) {\n\t\t\t\t\t// For each filter, check if it matches this document\n\t\t\t\t\tfor (const item of additionalFilters) {\n\t\t\t\t\t\tif (sift(item.filter)(doc)) {\n\t\t\t\t\t\t\tif (item.opIndex !== null) {\n\t\t\t\t\t\t\t\t// For logs\n\t\t\t\t\t\t\t\tif (item.isUpdateMany || item.isDeleteMany) {\n\t\t\t\t\t\t\t\t\t// For updateMany and deleteMany, we collect multiple documents\n\t\t\t\t\t\t\t\t\tif (!logs[item.opIndex].insertMany) {\n\t\t\t\t\t\t\t\t\t\tlogs[item.opIndex].insertMany = [];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tlogs[item.opIndex].insertMany.push({\n\t\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\t\t\t\t\tpayload:\n\t\t\t\t\t\t\t\t\t\t\tgetBinarySize(JSON.stringify([operations[item.opIndex], options])) < 200000\n\t\t\t\t\t\t\t\t\t\t\t\t? JSON.stringify([operations[item.opIndex], options], null, 2)\n\t\t\t\t\t\t\t\t\t\t\t\t: 'Too Big',\n\t\t\t\t\t\t\t\t\t\tmethod: operations[item.opIndex] ? Object.keys(operations[item.opIndex])[0] : '',\n\t\t\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if (item.isSingle) {\n\t\t\t\t\t\t\t\t\t// For updateOne and deleteOne without _id in filter\n\t\t\t\t\t\t\t\t\tlogs[item.opIndex].insertOne.document.id_document = doc._id;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// For versioning\n\t\t\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\t\t\tmodifiedIds.add(<string>doc._id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t// Perform the bulkWrite operations\n\t\t\tconst mainResult = await ResolveIOServer.getMainDB()\n\t\t\t\t.collection<T>(this.collectionName)\n\t\t\t\t.bulkWrite(bulkOps, options);\n\t\n\t\t\t// Versioning using aggregation pipeline\n\t\t\tif (this.useVersions && modifiedIds.size > 0) {\n\t\t\t\tconst modifiedIdsArray = Array.from(modifiedIds);\n\t\n\t\t\t\t// Create versions using aggregation\n\t\t\t\tResolveIOServer.getMainDB()\n\t\t\t\t\t.collection<T>(this.collectionName)\n\t\t\t\t\t.aggregate([\n\t\t\t\t\t\t{ $match: { _id: { $in: modifiedIdsArray } } },\n\t\t\t\t\t\t{ $addFields: { '_id': { _id: '$_id', __v: '$__v' } } },\n\t\t\t\t\t\t{ $project: { '__v': 0 } },\n\t\t\t\t\t\t{ $merge: {\n\t\t\t\t\t\t\tinto: this.versionCollection,\n\t\t\t\t\t\t\ton: '_id',\n\t\t\t\t\t\t\twhenMatched: 'fail',\n\t\t\t\t\t\t\twhenNotMatched: 'insert'\n\t\t\t\t\t\t}}\n\t\t\t\t\t])\n\t\t\t\t\t.toArray();\n\t\n\t\t\t\t// Delete old versions without loops\n\t\t\t\tconst oldVersions = await ResolveIOServer.getMainDB()\n\t\t\t\t\t.collection<T>(this.versionCollection)\n\t\t\t\t\t.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t'_id._id': { $in: modifiedIdsArray }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$sort: {\n\t\t\t\t\t\t\t\t'_id._id': 1,\n\t\t\t\t\t\t\t\t'_id.__v': -1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: '$_id._id',\n\t\t\t\t\t\t\t\tdocs: { $push: '$_id' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\t\t\tdocsToDelete: {\n\t\t\t\t\t\t\t\t\t$slice: ['$docs', 5, { $size: '$docs' }]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ $unwind: '$docsToDelete' },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$replaceRoot: { newRoot: '$docsToDelete' }\n\t\t\t\t\t\t}\n\t\t\t\t\t])\n\t\t\t\t\t.toArray();\n\t\n\t\t\t\tif (oldVersions.length > 0) {\n\t\t\t\t\tResolveIOServer.getMainDB()\n\t\t\t\t\t\t.collection<T>(this.versionCollection)\n\t\t\t\t\t\t.deleteMany(<any>{ _id: { $in: oldVersions } });\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t// Perform logging if necessary\n\t\t\tif (!bypassLogs && logs.length) {\n\t\t\t\t// For logs with insertMany (updateMany, deleteMany), we need to expand them\n\t\t\t\tconst expandedLogs = [];\n\t\t\t\tfor (const log of logs) {\n\t\t\t\t\tif (log.insertOne) {\n\t\t\t\t\t\texpandedLogs.push(log);\n\t\t\t\t\t}\n\t\t\t\t\telse if (log.insertMany) {\n\t\t\t\t\t\tfor (const doc of log.insertMany) {\n\t\t\t\t\t\t\texpandedLogs.push({\n\t\t\t\t\t\t\t\tinsertOne: {\n\t\t\t\t\t\t\t\t\tdocument: doc\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\n\t\t\t\tif (expandedLogs.length) {\n\t\t\t\t\tLogs.bulkWrite(expandedLogs, { ordered: false });\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t// Invalidate cache\n\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\n\t\t\treturn mainResult;\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error('Error in bulkWrite:', err);\n\t\t\tthrow err;\n\t\t}\n\t}\n\t\n\t// Helper function to extract field names from filters\n\tprivate extractFieldNames(filter: any, fieldNamesSet: Set<string>, prefix = '') {\n\t\tif (typeof filter !== 'object' || filter == null) {\n\t\t\treturn;\n\t\t}\n\t\n\t\tfor (const key in filter) {\n\t\t\tconst value = filter[key];\n\t\t\tif (key.startsWith('$')) {\n\t\t\t\t// Logical operator ($and, $or, etc.)\n\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\tvalue.forEach(subFilter => this.extractFieldNames(subFilter, fieldNamesSet, prefix));\n\t\t\t\t}\n\t\t\t\telse if (typeof value === 'object') {\n\t\t\t\t\tthis.extractFieldNames(value, fieldNamesSet, prefix);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconst fullPath = prefix ? `${prefix}.${key}` : key;\n\t\t\t\tif (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n\t\t\t\t\t// May contain operators like $eq, $gt, etc.\n\t\t\t\t\tfieldNamesSet.add(fullPath);\n\t\t\t\t\tthis.extractFieldNames(value, fieldNamesSet, fullPath);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfieldNamesSet.add(fullPath);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tcountDocuments(\n\t\tfilter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {},\n\t\toptions?: CountDocumentsOptions,\n\t\tskipCache = false\n\t): Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\ttry {\n\t\t\t\t// Check if the filter is empty\n\t\t\t\tconst isUnfiltered = Object.keys(filter).length === 0;\n\t\n\t\t\t\tif (isUnfiltered) {\n\t\t\t\t\t// Use collection stats for an unfiltered count\n\t\t\t\t\tconst res = await ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).estimatedDocumentCount(options);\n\t\t\t\t\tresolve(res);\n\t\t\t\t}\n\t\t\t\telse if (!skipCache) {\n\t\t\t\t\t// Use cached count if skipCache is false\n\t\t\t\t\tResolveIOServer.getMongoManager().countDocuments(this.collectionName, filter, options).then(\n\t\t\t\t\t\tres => resolve(res),\n\t\t\t\t\t\terr => reject(err)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// Fallback to direct countDocuments call with monitoring if skipCache is true\n\t\t\t\t\tlet monitor = new MonitorMongo('countDocuments', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).countDocuments(<any>filter, options).then(\n\t\t\t\t\t\tres => {\n\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\tresolve(res);\n\t\t\t\t\t\t},\n\t\t\t\t\t\terr => {\n\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Error Count Documents', this.collectionName, filter, options, err);\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconsole.log(new Date(), 'Error Count Documents (Stats)', this.collectionName, filter, options, err);\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t}\n\n\t//Helper Function (1 or Many) - Not Real Mongo Function\n\tcreate(f_docs: T | T[], options?: InsertOneOptions | BulkWriteOptions): Promise<T | T[]> {\n\t\tif (!Array.isArray(f_docs)) {\n\t\t\treturn this.insertOne(f_docs, <InsertOneOptions>options);\n\t\t}\n\t\telse if (f_docs.length === 1) {\n\t\t\treturn this.insertOne(f_docs[0], <InsertOneOptions>options);\n\t\t}\n\n\t\treturn this.insertMany(f_docs, <BulkWriteOptions>options);\n\t}\n\n\tcreateIndex(fieldOrSpec: any, options?: CreateIndexesOptions): Promise<string> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\ttry {\n\t\t\t\t// Check if index already exists based on the key\n\t\t\t\tconst dbCollection = ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions);\n\t\t\t\tconst existingIndexes = await dbCollection.indexes();\n\t\n\t\t\t\t// Check if an index with the same key already exists\n\t\t\t\tconst indexExists = existingIndexes.some(index => \n\t\t\t\t\tJSON.stringify(index.key) === JSON.stringify(fieldOrSpec)\n\t\t\t\t);\n\t\n\t\t\t\tif (indexExists) {\n\t\t\t\t\treturn resolve('Index already exists'); // Skip creation if index exists\n\t\t\t\t}\n\t\n\t\t\t\t// If index doesn't exist, push it to the queue\n\t\t\t\tMongoManagerCollection.indexQueue.push({\n\t\t\t\t\taction: 'createIndex',\n\t\t\t\t\tcollection: this,\n\t\t\t\t\tspecs: [fieldOrSpec],\n\t\t\t\t\toptions: options\n\t\t\t\t}, (err, result) => {\n\t\t\t\t\tif (err) reject(err);\n\t\t\t\t\telse resolve(result);\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t}\n\t\n\tcreateIndexes(indexSpecs: IndexDescription[], options?: CreateIndexesOptions): Promise<string[]> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\ttry {\n\t\t\t\tconst dbCollection = ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions);\n\t\t\t\tconst existingIndexes = await dbCollection.indexes();\n\t\n\t\t\t\t// Filter out indexes that already exist based on the key\n\t\t\t\tconst indexesToCreate = indexSpecs.filter(indexSpec => \n\t\t\t\t\t!existingIndexes.some(existingIndex => \n\t\t\t\t\t\tJSON.stringify(existingIndex.key) === JSON.stringify(indexSpec.key)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\n\t\t\t\t// If no new indexes to create, resolve early\n\t\t\t\tif (indexesToCreate.length === 0) {\n\t\t\t\t\treturn resolve(['All indexes already exist']);\n\t\t\t\t}\n\t\n\t\t\t\t// Push only new indexes to the queue\n\t\t\t\tMongoManagerCollection.indexQueue.push({\n\t\t\t\t\taction: 'createIndexes',\n\t\t\t\t\tcollection: this,\n\t\t\t\t\tspecs: [indexesToCreate],\n\t\t\t\t\toptions: options\n\t\t\t\t}, (err, result) => {\n\t\t\t\t\tif (err) reject(err);\n\t\t\t\t\telse resolve(result);\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t}\n\t\n\n\tdeleteMany(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: DeleteOptions, bypassLogs = false): Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\tlet docs = await this.find(filter);\n\n\t\t\t\tfor (let i = 0; i < docs.length; i++) {\n\t\t\t\t\tlet doc = docs[i];\n\t\t\t\t\n\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',\n\t\t\t\t\t\tmethod: 'deleteMany',\n\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\troute: ''\n\t\t\t\t\t});\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 1}}]});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('deleteMany', this.collectionName, JSON.stringify([filter, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).deleteMany(<any>filter, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\tresolve(res.deletedCount);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Delete Many', this.collectionName, filter, options, err);\n\t\t\t\treject(err)\n\t\t\t});\n\t\t});\n\t}\n\n\tdeleteOne(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOneAndDeleteOptions, bypassLogs = false): Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\tlet monitor = new MonitorMongo('findOneAndDelete', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndDelete(<any>filter, options).then(async returnVal => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tlet doc = returnVal;\n\n\t\t\t\t\tif (doc) {\n\t\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'deleteOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\t\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 1}}]});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\n\t\t\t\t\t\tresolve(1);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tresolve(0);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Find One And Delete', this.collectionName, filter, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet monitor = new MonitorMongo('deleteOne', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).deleteOne(<any>filter, options).then(res => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\tresolve(res.deletedCount);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Delete One', this.collectionName, filter, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\t\t\t\n\t\t});\n\t}\n\n\tdistinct(key: string, filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: CommandOperationOptions): Promise<T[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('distinct', this.collectionName, JSON.stringify([key, filter, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).distinct(key, <any>filter, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Distinct', this.collectionName, filter, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tdrop(options?: CommandOperationOptions): Promise<boolean> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('drop', this.collectionName, JSON.stringify([options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).drop(options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Count Documents', this.collectionName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tdropIndex(indexName: string, options?: CommandOperationOptions): Promise<Document> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('dropIndex', this.collectionName, JSON.stringify([indexName, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).dropIndex(indexName, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(<Document>res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Drop Index', this.collectionName, indexName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tdropIndexes(options?: CommandOperationOptions): Promise<Boolean> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('dropIndexes', this.collectionName, JSON.stringify([options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).dropIndexes(options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Drop Indexes', this.collectionName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tfind(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>, skipCache = false): Promise<T[]> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!skipCache) {\n\t\t\t\tResolveIOServer.getMongoManager().find(this.collectionName, filter, options).then(res => {\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet monitor = new MonitorMongo('find', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).find<T>(<any>filter, options).toArray().then(res => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Find', this.collectionName, filter, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tfindById(id: string, options?: FindOptions<T>): Promise<T> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('findById', this.collectionName, JSON.stringify([{_id: id}, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOne<T>(<any>{_id: id}, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find By Id', this.collectionName, {_id: id}, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tfindCount(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>): Promise<Number> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('findCount', this.collectionName, JSON.stringify([filter, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).find(<any>filter, options).count().then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find Count', this.collectionName, filter, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tfindCursor(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>): FindCursor {\n\t\tlet monitor = new MonitorMongo('findCursor', this.collectionName, JSON.stringify([filter, options]));\n\t\tlet cursor = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).find(<any>filter, options);\n\t\tcursor.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\tcursor.removeAllListeners();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn cursor;\n\t}\n\n\tfindStream(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>, streamOptions?: CursorStreamOptions) {\n\t\tlet monitor = new MonitorMongo('findStream', this.collectionName, JSON.stringify([filter, options, streamOptions]));\n\t\tlet stream = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).find(<any>filter, options).stream(streamOptions);\n\t\tstream.on('end', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t})\n\t\t.on('error', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t})\n\t\t.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn stream;\n\t}\n\n\tfindOne(filter: MongoManagerFilter<T> | MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>, skipCache = false): Promise<T> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tif (!skipCache) {\n\t\t\t\tResolveIOServer.getMongoManager().findOne(this.collectionName, filter, options).then(res => {\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet monitor = new MonitorMongo('findOne', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOne<T>(<any>filter, options).then(res => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Find One', this.collectionName, filter, options, err);\n\t\t\t\t\treject(err)\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tfindOneAndDelete(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOneAndDeleteOptions, bypassLogs = false): Promise<T> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('findOneAndDelete', this.collectionName, JSON.stringify([filter, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndDelete(<any>filter, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tlet doc = res;\n\t\t\t\t\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'findOneAndDelete',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t}\n\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\n\t\t\t\t\tresolve(<T>doc);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresolve(null);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find One And Delete', this.collectionName, filter, options, err);\n\t\t\t\treject(err)\n\t\t\t});\n\t\t});\n\t}\n\n\tfindOneAndReplace(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, replacement: T, options?: FindOneAndReplaceOptions, bypassLogs = false, bypassCheckSchema = false): Promise<T> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(replacement);\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - findOneAndReplace', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on findOneAndReplace - ' + this.collectionName, [validation.validationErrors(), replacement]);\n\t\t\t\t\t\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tlet date = new Date();\n\n\t\t\tif (this.timestamps) {\n\t\t\t\treplacement.updatedAt = date;\n\t\t\t}\n\n\t\t\tif (options && options.upsert) {\n\t\t\t\tif (!replacement._id) {\n\t\t\t\t\treplacement._id = objectIdHexString();\n\t\t\t\t}\n\n\t\t\t\tif (this.useVersions) {\n\t\t\t\t\treplacement.__v = 0;\n\t\t\t\t}\n\n\t\t\t\tif (this.timestamps && !replacement.createdAt) {\n\t\t\t\t\treplacement.createdAt = date;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('findOneAndReplace', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndReplace(<any>filter, replacement, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tlet doc = res;\n\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'findOneAndReplace',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t}\n\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\n\t\t\t\t\tresolve(<T>doc);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresolve(null);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find One And Replace', this.collectionName, filter, options, err);\n\t\t\t\treject(err)\n\t\t\t});\n\t\t});\n\t}\n\n\tfindOneAndUpdate(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, update: MongoManagerUpdateFilter<T>, options?: FindOneAndUpdateOptions, bypassLogs = false, bypassCheckSchema = false): Promise<T> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(update, {modifier: true});\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - findOneAndUpdate', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on findOneAndUpdate - ' + this.collectionName, [validation.validationErrors(), update]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.timestamps) {\n\t\t\t\tlet date = new Date(); \n\t\t\t\t\n\t\t\t\tif (!update.$set) {\n\t\t\t\t\tupdate.$set = <any>{updatedAt: date};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tupdate.$set.updatedAt = date;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options && options.upsert) {\n\t\t\t\tif (!update.$setOnInsert) {\n\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\tcreatedAt: new Date()\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t_id: objectIdHexString()\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (!update.$setOnInsert._id) {\n\t\t\t\t\t\tupdate.$setOnInsert._id = objectIdHexString();\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.timestamps && !update.$setOnInsert.createdAt) {\n\t\t\t\t\t\tupdate.$setOnInsert.createdAt = new Date();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('findOneAndUpdate', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndUpdate(<any>filter, <any>update, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tlet doc = res;\n\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\t\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'findOneAndUpdate',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t}\n\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\n\t\t\t\t\tresolve(<T>doc);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresolve(null);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find One And Update', this.collectionName, filter, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tindexes(options: IndexInformationOptions): Promise<any[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('indexes', this.collectionName, JSON.stringify([options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).indexes(options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Indexes', this.collectionName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tindexExists(indexes: string | string[], options?: IndexInformationOptions): Promise<boolean> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('indexExists', this.collectionName, JSON.stringify([indexes, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).indexExists(indexes, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Index Exists', this.collectionName, indexes, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tinsertMany(docs: T[], options?: BulkWriteOptions, bypassLogs = false, bypassCheckSchema = false, bypassMonitor = false): Promise<T[]> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!docs.length) {\n\t\t\t\tresolve([]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tlet validationResults = [];\n\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tdocs.forEach(doc => {\n\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\tconst isValid = validation.validate(doc);\n\n\t\t\t\t\tif (!isValid) {\n\t\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - insertMany', validation.validationErrors());\n\t\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on insertMany - ' + this.collectionName, [validation.validationErrors(), doc]);\n\t\t\t\t\t\tvalidationResults.push(false);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tvalidationResults.push(true);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet validDocs = this.checkSchema ? docs.filter((a, idx) => validationResults[idx]) : docs;\n\n\t\t\tfor (let i = 0; i < validDocs.length; i++) {\n\t\t\t\tlet doc = validDocs[i];\n\n\t\t\t\tif (!doc._id) {\n\t\t\t\t\tdoc._id = objectIdHexString();\n\t\t\t\t}\n\n\t\t\t\tif (this.timestamps) {\n\t\t\t\t\tlet date = new Date();\n\n\t\t\t\t\tif (!doc.createdAt) {\n\t\t\t\t\t\tdoc.createdAt = date;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!doc.updatedAt) {\n\t\t\t\t\t\tdoc.updatedAt = date;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this.useVersions && !doc.hasOwnProperty('__v')) {\n\t\t\t\t\tdoc.__v = 0;\n\t\t\t\t}\n\n\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',\n\t\t\t\t\t\tmethod: 'insertMany',\n\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\troute: ''\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (validDocs.length) {\n\t\t\t\tlet monitor = null;\n\t\t\t\t\n\t\t\t\tif (!bypassMonitor) {\n\t\t\t\t\tmonitor = new MonitorMongo('insertMany', this.collectionName, JSON.stringify([validDocs, options]));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).insertMany(<OptionalUnlessRequiredId<T>[]>validDocs, options).then(res => {\n\t\t\t\t\tif (monitor) {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t}\n\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\tresolve(validDocs);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tif (monitor) {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t}\n\t\t\t\t\tconsole.log(new Date(), 'Error Insert Many', this.collectionName, validDocs, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tinsertOne(doc: T, options?: InsertOneOptions, bypassLogs = false, bypassCheckSchema = false): Promise<T> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!doc._id) {\n\t\t\t\tdoc._id = objectIdHexString();\n\t\t\t}\n\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(doc);\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - insertOne', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on insertOne - ' + this.collectionName, [validation.validationErrors(), doc]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.timestamps) {\n\t\t\t\tlet date = new Date();\n\t\t\t\n\t\t\t\tif (!doc.createdAt) {\n\t\t\t\t\tdoc.createdAt = date;\n\t\t\t\t}\n\n\t\t\t\tif (!doc.updatedAt) {\n\t\t\t\t\tdoc.updatedAt = date;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\tLogs.insertOne({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\ttype: 'document',\n\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',\n\t\t\t\t\tmethod: 'insertOne',\n\t\t\t\t\tid_user: '',\n\t\t\t\t\tuser: '',\n\t\t\t\t\tmessageId: 0,\n\t\t\t\t\troute: ''\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (this.useVersions && !doc.hasOwnProperty('__v')) {\n\t\t\t\tdoc.__v = 0;\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('insertOne', this.collectionName, JSON.stringify([doc, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).insertOne(<OptionalUnlessRequiredId<T>>doc, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\tresolve(doc);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Insert One', this.collectionName, doc, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tlistIndexes(options?: ListIndexesOptions): ListIndexesCursor {\n\t\tlet monitor = new MonitorMongo('listIndexes', this.collectionName, JSON.stringify([options]));\n\t\tlet cursor = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).listIndexes(options);\n\t\tcursor.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn cursor;\n\t}\n\n\trename(newName: string, options?: RenameOptions): Promise<Collection<Document>> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('rename', this.collectionName, JSON.stringify([newName, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).rename(newName, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Rename', this.collectionName, newName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\treplaceOne(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, replacement: T, options?: ReplaceOptions, bypassLogs = false, bypassCheckSchema = false, doc: T = null) : Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(replacement);\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - replaceOne', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on replaceOne - ' + this.collectionName, [validation.validationErrors(), replacement]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tlet date = new Date();\n\t\t\t\n\t\t\tif (this.timestamps) {\n\t\t\t\treplacement.updatedAt = date;\n\t\t\t}\n\n\t\t\tif (this.useVersions) {\n\t\t\t\tif (!doc) {\n\t\t\t\t\tdoc = await this.findOne(<any>filter, null, true);\n\t\t\t\t}\n\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.timestamps && !replacement.createdAt && doc.createdAt) {\n\t\t\t\t\t\treplacement.createdAt = doc.createdAt;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (doc.__v === replacement.__v) {\n\t\t\t\t\t\treplacement.__v += 1;\n\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\n\t\t\t\t\t\tif (doc.__v >= 4) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 4}}]});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tlet monitor = new MonitorMongo('replaceOne', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).replaceOne(<any>filter, replacement, options).then(res => {\n\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, err => {\n\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Error Replace One', this.collectionName, filter, replacement, options, err);\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tconsole.log('invalid version - ' + this.collectionName, doc.__v, replacement.__v);\n\n\t\t\t\t\t\tlet prevDoc = await ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({\n\t\t\t\t\t\t\t_id: <any>{\n\t\t\t\t\t\t\t\t_id: doc._id,\n\t\t\t\t\t\t\t\t__v: replacement.__v\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, null, true);\n\n\t\t\t\t\t\tif (prevDoc) {\n\t\t\t\t\t\t\tlet docId = doc._id;\n\t\t\t\t\t\t\tlet docVersion = doc.__v;\n\t\t\t\t\t\t\tlet updatedDoc: T = getMongoMergeUpdatedDoc(replacement, doc, prevDoc);\n\t\t\t\t\t\t\tupdatedDoc._id = docId;\n\t\t\t\t\t\t\tupdatedDoc.__v = docVersion + 1;\n\n\t\t\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\t\tid_document: docId,\n\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['invalidVersion - merge', doc, filter, updatedDoc, options])) < 200000 ? JSON.stringify(['invalidVersion - merge', doc, filter, updatedDoc, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet monitor = new MonitorMongo('replaceOne', this.collectionName, JSON.stringify([filter, updatedDoc, options]));\n\t\t\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).replaceOne(<any>filter, updatedDoc, options).then(res => {\n\t\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, err => {\n\t\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Error Replace One', this.collectionName, filter, updatedDoc, options, err);\n\t\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject('Invalid Version And Could Not Find History - DB: ' + doc.__v + ', Trying to update with :' + replacement.__v);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (options && options.upsert) {\n\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\treplacement.createdAt = date;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!replacement._id) {\n\t\t\t\t\t\treplacement._id = objectIdHexString();\n\t\t\t\t\t}\n\n\t\t\t\t\treplacement.__v = 0;\n\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: replacement._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['upsert', filter, replacement, options])) < 200000 ? JSON.stringify(['upsert', filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tlet monitor = new MonitorMongo('replaceOne', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).replaceOne(<any>filter, replacement, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Replace One', this.collectionName, filter, replacement, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject('No Document');\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (options && options.upsert) {\n\t\t\t\t\tif (this.timestamps && !replacement.createdAt) {\n\t\t\t\t\t\treplacement.createdAt = date;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!replacement._id) {\n\t\t\t\t\t\treplacement._id = objectIdHexString();\n\t\t\t\t\t}\n\n\t\t\t\t\treplacement.__v = 0;\n\t\t\t\t}\n\n\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\tif (!options) {\n\t\t\t\t\t\toptions = <FindOneAndReplaceOptions>{returnDocument: 'before'};\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t(<FindOneAndReplaceOptions>options).returnDocument = 'before';\n\t\t\t\t\t}\n\n\t\t\t\t\tlet monitor = new MonitorMongo('findOneAndReplace', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndReplace(<any>filter, replacement, <FindOneAndReplaceOptions>options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tlet doc = res;\n\n\t\t\t\t\t\tif (doc) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: replacement._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['upsert', filter, replacement, options])) < 200000 ? JSON.stringify(['upsert', filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\tresolve(1);\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Find One And Replace', this.collectionName, filter, replacement, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet monitor = new MonitorMongo('replaceOne', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).replaceOne(<any>filter, replacement, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Replace One', this.collectionName, filter, replacement, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tupdateMany(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, update: MongoManagerUpdateFilter<T>, options?: UpdateOptions, bypassLogs = false, bypassCheckSchema = false, bypassVersions = false) : Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif ((!update.$inc || JSON.stringify(update.$inc) === '{}') && (!update.$set || JSON.stringify(update.$set) === '{}') && (!update.$setOnInsert || JSON.stringify(update.$setOnInsert) === '{}') && (!update.$unset || JSON.stringify(update.$unset) === '{}')) {\n\t\t\t\tresolve(1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tif (this.timestamps) {\n\t\t\t\tlet date = new Date();\n\n\t\t\t\tif (!update.$set) {\n\t\t\t\t\tupdate.$set = <any>{updatedAt: date};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tupdate.$set.updatedAt = date;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(update, {modifier: true});\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - updateMany', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on updateMany - ' + this.collectionName, [validation.validationErrors(), update]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((this.useVersions && !bypassVersions) || (this.createLogs && !bypassLogs)) {\n\t\t\t\tlet docs = await this.find(filter);\n\t\n\t\t\t\tfor (let i = 0; i < docs.length; i++) {\n\t\t\t\t\tlet doc = docs[i];\n\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'updateMany',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\t\t\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (doc.__v >= 4) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 4}}]});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (!objectContainsPropertyDeep(update, '__v')) {\n\t\t\t\t\t\t\tif (!update.$inc) {\n\t\t\t\t\t\t\t\tupdate.$inc = {__v: 1};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (!update.$inc.__v) {\n\t\t\t\t\t\t\t\tupdate.$inc.__v = 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('updateMany', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateMany(<any>filter, update, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Update Many', this.collectionName, filter, update, options, err);\n\t\t\t\treject(err)\n\t\t\t});\n\t\t});\n\t}\n\n\tupdateOne(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, update: MongoManagerUpdateFilter<T>, options?: UpdateOptions, bypassLogs = false, bypassCheckSchema = false) : Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\t\t\t\n\t\t\t\tconst isValid = validation.validate(update, {modifier: true});\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - updateOne', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on updateOne - ' + this.collectionName, [validation.validationErrors(), update]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((!update.$inc || JSON.stringify(update.$inc) === '{}') && (!update.$set || JSON.stringify(update.$set) === '{}') && (!update.$setOnInsert || JSON.stringify(update.$setOnInsert) === '{}') && (!update.$unset || JSON.stringify(update.$unset) === '{}')) {\n\t\t\t\tresolve(1);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet date = new Date();\n\n\t\t\tif (this.timestamps) {\n\t\t\t\tif (!update.$set) {\n\t\t\t\t\tupdate.$set = <any>{updatedAt: date};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tupdate.$set.updatedAt = date;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (this.useVersions) {\n\t\t\t\tlet doc = await this.findOne(filter, null, true);\n\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'updateOne',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\t\n\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t\n\t\t\t\t\tif (doc.__v >= 4) {\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 4}}]});\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (!objectContainsPropertyDeep(update, '__v')) {\n\t\t\t\t\t\tif (!update.$inc) {\n\t\t\t\t\t\t\tupdate.$inc = {__v: 1};\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (!update.$inc.__v) {\n\t\t\t\t\t\t\tupdate.$inc.__v = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tlet monitor = new MonitorMongo('updateOne', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateOne(<any>filter, update, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Update One', this.collectionName, filter, update, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse if (options && options.upsert) {\n\t\t\t\t\tif (!update.$setOnInsert) {\n\t\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\tcreatedAt: new Date()\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t__v: 0\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (!update.$setOnInsert._id) {\n\t\t\t\t\t\t\tupdate.$setOnInsert._id = objectIdHexString();\n\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\tif (this.timestamps && !update.$setOnInsert.createdAt) {\n\t\t\t\t\t\t\tupdate.$setOnInsert.createdAt = new Date();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: update.$setOnInsert._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['upsert', filter, update, options])) < 200000 ? JSON.stringify(['upsert', filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'updateOne',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tlet monitor = new MonitorMongo('updateOne', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateOne(<any>filter, update, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Update One', this.collectionName, filter, update, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject('No Document');\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (options && options.upsert) {\n\t\t\t\t\tif (!update.$setOnInsert) {\n\t\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\tcreatedAt: new Date()\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t\t_id: objectIdHexString()\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (!update.$setOnInsert._id) {\n\t\t\t\t\t\t\tupdate.$setOnInsert._id = objectIdHexString();\n\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\tif (this.timestamps && !update.$setOnInsert.createdAt) {\n\t\t\t\t\t\t\tupdate.$setOnInsert.createdAt = new Date();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\tif (!options) {\n\t\t\t\t\t\toptions = <FindOneAndUpdateOptions>{returnDocument: 'before'};\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t(<FindOneAndUpdateOptions>options).returnDocument = 'before';\n\t\t\t\t\t}\n\n\t\t\t\t\tlet monitor = new MonitorMongo('findOneAndUpdate', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).findOneAndUpdate(<any>filter, update, <FindOneAndUpdateOptions>options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tlet doc = res.value;\n\n\t\t\t\t\t\tif (doc) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: <any>doc._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'updateOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tresolve(res.ok);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (update.$setOnInsert) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: update.$setOnInsert._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['upsert', filter, update, options])) < 200000 ? JSON.stringify(['upsert', filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'updateOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\n\t\t\t\t\t\t\tresolve(res.ok);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tresolve(0);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Find One And Update', this.collectionName, filter, update, options, err);\n\t\t\t\t\t\treject(err)\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet monitor = new MonitorMongo('updateOne', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateOne(<any>filter, update, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Update One', this.collectionName, filter, update, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t\n\twatchCollection(pipeline = [], options?: ChangeStreamOptions): ChangeStream<T> {\n\t\tlet stream = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).watch(pipeline, options);\n\t\treturn <ChangeStream<T>>stream;\n\t}\n}\n\nexport class MongoManagerUserCollection<T extends CollectionDocument> extends MongoManagerCollection<T> {\n\tauthenticate(user: UserModel, password: string): Promise<{data: UserModel, error: string}> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tconst attemptsInterval = Math.pow(100, Math.log(user.attempts + 1));\n\t\t\tconst calculatedInterval = attemptsInterval < 300000 ? attemptsInterval : 300000;\n\t\t\n\t\t\tif (user.last) {\n\t\t\t\tif (Date.now() - user.last.getTime() < calculatedInterval) {\n\t\t\t\t\tuser.last = new Date();\n\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {last: user.last}});\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: 'Attempt Too Soon'\n\t\t\t\t\t});\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tuser.last = new Date();\n\t\t\t}\n\t\t\n\t\t\tif (user.attempts >= 5) {\n\t\t\t\tresolve({\n\t\t\t\t\tdata: null,\n\t\t\t\t\terror: 'Too Many Attempts'\n\t\t\t\t});\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tif (!user.salt) {\n\t\t\t\tresolve({\n\t\t\t\t\tdata: null,\n\t\t\t\t\terror: 'No Salt Value Stored'\n\t\t\t\t});\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tpbkdf2(password, user.salt, {\n\t\t\t\titerations: 25000,\n\t\t\t\tkeylen: 512,\n\t\t\t\tdigestAlgorithm: 'sha256'\n\t\t\t}, async (err, hashBuffer) => {\n\t\t\t\tif (err) {\n\t\t\t\t\treturn reject(err);\n\t\t\t\t}\n\t\t\t\n\t\t\t\tif (scmp(hashBuffer, Buffer.from(user.hash, 'hex'))) {\n\t\t\t\t\tuser.last = new Date();\n\t\t\t\t\tuser.attempts = 0;\n\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {last: user.last, attempts: user.attempts}});\n\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tdata: user,\n\t\t\t\t\t\terror: ''\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tuser.last = new Date();\n\t\t\t\t\tuser.attempts = user.attempts + 1;\n\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {last: user.last, attempts: user.attempts}});\n\n\t\t\t\t\tif (user.attempts >= 5) {\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\terror: 'Too Many Attempts'\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\terror: 'Invalid Username And Password'\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} \n\t\t\t});\n\t\t});\n\t}\n\n\tserializeUser() {\n\t\treturn (user, cb) => {\n\t\t\tcb(null, user.username);\n\t\t};\n\t}\n\n\tdeserializeUser() {\n\t\treturn (username, cb) => {\n\t\t\tUsers.findOne({username: username}).then(res => {\n\t\t\t\tcb(null, res);\n\t\t\t}, err => {\n\t\t\t\tcb(err, null);\n\t\t\t});\n\t\t};\n\t}\n\n\tsetPassword(user: UserModel, password: string) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!user) {\n\t\t\t\treject('No User');\n\t\t\t}\n\t\t\telse if (!password) {\n\t\t\t\treject('No Password');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet saltBuffer = await randomBytes(32);\n\t\t\t\tlet salt = saltBuffer.toString('hex');\n\t\t\t\tlet hashRaw = await pbkdf2Promisified(password, salt, {\n\t\t\t\t\titerations: 25000,\n\t\t\t\t\tkeylen: 512,\n\t\t\t\t\tdigestAlgorithm: 'sha256'\n\t\t\t\t});\n\t\t\t\tlet hash = Buffer.from(hashRaw, 'binary').toString('hex');\n\t\t\t\tUsers.updateOne({_id: user._id}, {$set: {hash: hash, salt: salt, services: {}, attempts: 0}}).then(res => resolve(res), rej => reject(rej));\n\t\t\t}\n\t\t});\n\t};\n\n\tchangePassword(user, oldPassword, newPassword) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!user) {\n\t\t\t\treject('Missing User');\n\t\t\t}\n\t\t\telse if (!oldPassword || !newPassword) {\n\t\t\t\treject('Missing Password');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet authUser = await this.authenticate(user, oldPassword);\n\n\t\t\t\tif (!authUser['data']) {\n\t\t\t\t\treject(authUser['error']);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis.setPassword(user, newPassword).then(res => resolve(res), rej => reject(rej));\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t\n\tregister(user, password) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!user.username) {\n\t\t\t\treject('Missing Username');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet dbUser = await Users.findOne({username: user.username});\n\t\t\t\t\n\t\t\t\tif (dbUser) {\n\t\t\t\t\treject('Username Exists');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdbUser = await Users.findOne({email: user.email});\n\n\t\t\t\t\tif (dbUser) {\n\t\t\t\t\t\treject('Email Exists');\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tuser.setPassword(password);\n\t\t\t\t\t\tresolve(user);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tresetAttempts(user: UserModel) {\n\t\treturn Users.updateOne({_id: user._id}, {$set: {attempts: 0}});\n\t}\n}\n\nexport function objectIdHexString() {\n\tlet objectId = new ObjectId();\n\treturn objectId.toHexString();\n}\n\nfunction pbkdf2(password, salt, options, callback) {\n\tcrypto.pbkdf2(password, salt, options.iterations, options.keylen, options.digestAlgorithm, callback);\n};\n\nfunction pbkdf2Promisified(password, salt, options): Promise<any> {\n\treturn new Promise((resolve, reject) => pbkdf2(password, salt, options, (err, hashRaw) => (err ? reject(err) : resolve(hashRaw))));\n}\n\nfunction randomBytes(saltlen): Promise<Buffer> {\n\treturn new Promise((resolve, reject) => crypto.randomBytes(saltlen, (err, saltBuffer) => (err ? reject(err) : resolve(saltBuffer))));\n}\n\nfunction objectContainsPropertyDeep(obj: Object, prop: string) {\n\tlet keys = Object.keys(obj);\n\n\tif (keys.some(a => a === prop)) {\n\t\treturn true;\n\t}\n\t\n\tfor (let i = 0; i < keys.length; i++) {\n\t\tlet key = keys[i];\n\t\tif (obj[key] && typeof obj[key] === 'object' && objectContainsPropertyDeep(obj[key], prop)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}"]}
1
+ {"version":3,"sources":["../../src/managers/mongo.manager.ts"],"names":["simpl_schema_1","require","mongodb_1","index_1","user_collection_1","common_1","log_collection_1","NodeCache","crypto","scmp","monitor_manager_1","os_1","numCPUs","cpus","length","v8","async_1","sift_1","MongoManager","serverConfig","this","_collections","_cacheMap","_operationInProgress","Map","_heapSize","getHeapStatistics","_serverCollections","_serverConfig","_isWorkersEnabled","_isWorkerInstance","_nodeCache","stdTTL","checkperiod","process","env","IS_WORKERS_ENABLED","IS_WORKER_INSTANCE","setCacheLimit","initServerCollections","setupChangeStream","prototype","_heapLimit","ResolveIOServer","getMainDB","listCollections","toArray","collections","_a","sent","getServerCollections","registerCollection","collection","_this","collectionOptions","timeseries","timeField","some","a","name","collectionName","type","dropCollection","then","createCollection","push","find","delay","ms","Promise","resolve","setTimeout","filter","options","cacheKey","generateCacheKey","undefined","result","getFromCache","has","get","promise","operation","executeFind","set","invalidatedDuringExecution","finally","delete","monitor","MonitorMongo","JSON","stringify","finish","addToCache","findOne","executeFindOne","aggregate","pipeline","__spreadArray","__read","flatMap","stage","$lookup","from","executeAggregate","countDocuments","executeCountDocuments","functionName","args","keyString","createHash","update","digest","cachedData","parse","dateReviver","error","del","data","getBinarySize","nodeCacheSize","getStats","vsize","deleteCount","keys","keys_1","__values","keys_1_1","next","done","key","value","console","log","invalidateQueryCache","collectionCacheMap","includes","collectionCacheMap_1","collectionCacheMap_1_1","cacheMap","changeStream","watch","$match","$and","ns.coll","$nin","$not","on","change","__awaiter","coll","err","Date","close","MongoManagerModel","exports","versionOptions","collection_main","collection_version","MongoManagerUserCollection","MongoManagerCollection","useVersionCollection","useVersions","versionSchema","deepCopy","schema","_id","blackbox","useReportBuilder","reportBuilderLookupTables","timestamps","createLogs","checkSchema","createIndex","_id._id","_id.__v","versionCollection","schemaCopy","interval","simplschema","rbSchema","useRB","default","buildRbLookups","buildRbSchema","setInterval","getMainServer","getMongoManager","clearInterval","extractIndexNameFromError","errorMessage","matches","match","skipCache","reject","monitor_1","res","aggregateCount","aggregateCursor","cursor","ev","aggregateStream","streamOptions","stream","bulkWrite","operations","bypassLogs","bypassCheckSchema","bypassVersions","bulkOps","logs","modifiedIds","Set","additionalFilters","fieldNamesSet","opIndex","op","opType","Object","doc","document","objectIdHexString","__v","date","createdAt","updatedAt","validation","newContext","validate","Error","concat","validationErrors","insertOne","id_document","payload","method","id_user","user","messageId","route","add","$set","$inc","upsert","$setOnInsert","modifier","replacement","isSingle","extractFieldNames","isUpdateMany","insertMany","isDeleteMany","combinedFilter","$or","map","item","projection_1","forEach","field","projection","docs","_h","docs_1","docs_1_1","e_4","additionalFilters_1","additionalFilters_1_1","mainResult","size","modifiedIdsArray","Array","$in","$addFields","$project","$merge","into","whenMatched","whenNotMatched","$sort","$group","$push","docsToDelete","$slice","$size","$unwind","$replaceRoot","newRoot","oldVersions","deleteMany","expandedLogs","logs_1","logs_1_1","e_6","_b","_c","Logs","ordered","err_1","prefix","startsWith","isArray","subFilter","fullPath","estimatedDocumentCount","monitor_2","err_2","create","f_docs","fieldOrSpec","indexes","existingIndexes","index","indexQueue","action","specs","err_3","createIndexes","indexSpecs","existingIndexes_1","indexesToCreate","indexSpec","existingIndex","err_4","i","versionDoc","replaceOne","$lt","acknowledged","deletedCount","deleteOne","monitor_3","findOneAndDelete","returnVal","monitor_4","distinct","drop","dropIndex","indexName","dropIndexes","monitor_5","findById","id","findCount","count","findCursor","removeAllListeners","findStream","monitor_6","findOneAndReplace","getMethodManager","callMethodInternal","call","findOneAndUpdate","indexExists","bypassMonitor","validationResults","validDocs","idx","hasOwnProperty","monitor_7","listIndexes","rename","newName","monitor_8","modifiedCount","prevDoc","docId","docVersion","updatedDoc_1","getMongoMergeUpdatedDoc","monitor_9","monitor_10","returnDocument","monitor_11","monitor_12","updateMany","$unset","objectContainsPropertyDeep","updateOne","monitor_13","monitor_14","monitor_15","ok","monitor_16","watchCollection","queue","task","callback","dbCollection","apply","code","err_5","message","existingIndexName","innerError_1","_super","__extends","authenticate","password","attemptsInterval","Math","pow","attempts","calculatedInterval","last","now","getTime","Users","salt","pbkdf2","iterations","keylen","digestAlgorithm","hashBuffer","Buffer","hash","serializeUser","cb","username","deserializeUser","setPassword","randomBytes","saltBuffer","toString","pbkdf2Promisified","hashRaw","services","rej","changePassword","oldPassword","newPassword","authUser","register","email","resetAttempts","ObjectId","toHexString","saltlen","obj","prop"],"mappings":"yxFAAAA,gB,yMAAAC,QAAA,cAAA,GACAC,UAAAD,Q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AAO6Z,YAAYgB,EAAS,SAAC9R,EAAK+Q,GAAe,OAAC/Q,EAAM2C,EAAO3C,CAAG,EAAIjF,EAAQgW,CAAU,CAAvC,CAAyC,CAA1F,CAA2F,CACpI,CAEA,SAAS7C,2BAA2B6D,EAAaC,GAChD,IAAI3T,EAAO8F,OAAO9F,KAAK0T,CAAG,EAE1B,GAAI1T,EAAKnE,KAAK,SAAAC,GAAK,OAAAA,IAAM6X,CAAN,CAAU,EAC5B,MAAO,CAAA,EAGR,IAAK,IAAIpH,EAAI,EAAGA,EAAIvM,EAAK9G,OAAQqT,CAAC,GAAI,CACrC,IAAIjM,EAAMN,EAAKuM,GACf,GAAImH,EAAIpT,IAA4B,UAApB,OAAOoT,EAAIpT,IAAqBuP,2BAA2B6D,EAAIpT,GAAMqT,CAAI,EACxF,MAAO,CAAA,C,CAIT,MAAO,CAAA,CACR,CA3Ma5R,QAAAI,2BAAAA,2BA2KbJ,QAAAkE,kBAAAA","file":"mongo.manager.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { AggregateOptions, AggregationCursor, BulkWriteOptions, ChangeStream, ChangeStreamOptions, CommandOperationOptions, CountDocumentsOptions, CreateCollectionOptions, CreateIndexesOptions, CursorStreamOptions, DeleteOptions, Filter, FindCursor, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, FindOptions, IndexDescription, IndexInformationOptions, InsertOneOptions, ListIndexesCursor, ListIndexesOptions, ObjectId, RenameOptions, ReplaceOptions, UpdateOptions, OptionalId, Collection, CollectionInfo, OptionalUnlessRequiredId, AnyBulkWriteOperation, BulkWriteResult, DbStatsOptions, ChangeStreamDocument } from 'mongodb';\nimport { LookupTables } from '../models/report-builder.model';\nimport { ResolveIOServer } from '../index';\nimport { Users } from '../collections/user.collection';\nimport { buildRbLookups, buildRbSchema, dateReviver, deepCopy, getBinarySize, getMongoMergeUpdatedDoc } from '../util/common';\nimport { UserModel } from '../models/user.model';\nimport { Logs } from '../collections/log.collection';\nimport * as NodeCache from 'node-cache';\nconst crypto = require('crypto');\nconst scmp = require('scmp');\nimport { MonitorMongo } from './monitor.manager';\nimport { CollectionDocument, Document } from '../models/collection-document.model';\nimport { cpus } from 'os';\nconst numCPUs = cpus().length;\nconst v8 = require('v8');\nimport async from 'async';\nimport sift from 'sift';\n\ninterface MongoQueueModel {\n\t_id: number,\n\tname_collection: string;\n\tlookup_collections: string[];\n\tname_function: string;\n\tdata_function: any[];\n\tname_function_addt: string;\n\tdata_function_addt: any[];\n\tcbs: Function[];\n\tcbs_next: Function[];\n\trunning: boolean;\n\tcacheId: number;\n\tinvalidateFlag: boolean;\n\tinvalidateCount: number;\n}\n\n// export declare interface MongoManagerFilterOperators<T> extends Document {\nexport declare interface MongoManagerFilterParamaterOperators<P> {\n\t$eq?: P;\n $gt?: P;\n $gte?: P;\n $in?: P extends Array<any> ? P : P[];\n $lt?: P;\n $lte?: P;\n $ne?: P;\n $nin?: P extends Array<any> ? P : P[];\n $not?: P extends string ? MongoManagerFilterParamaterOperators<P> | RegExpConstructor : MongoManagerFilterParamaterOperators<P>;\n $exists?: boolean;\n $expr?: any[]\n $regex?: P extends string ? RegExpConstructor | string : never;\n $options?: P extends string ? string : never;\n $geoIntersects?: {\n $geometry: Document;\n };\n $geoWithin?: Document;\n $near?: Document;\n $nearSphere?: Document;\n $maxDistance?: number;\n $all?: any[];\n $elemMatch?: Document;\n $size?: P extends any[] ? number : never;\n}\n\nexport declare interface MongoManagerFilterOperators<T> extends Document { //TODO: Remove extends document when I get answer on S.O.\n $and?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;\n $nor?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;\n $or?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;\n $text?: {\n $search: string;\n $language?: string;\n $caseSensitive?: boolean;\n $diacriticSensitive?: boolean;\n };\n $where?: string | ((this: T) => boolean);\n $comment?: string | Document;\n}\n\n// function isDotStringRegExp(obj: Object, dotKey: string): boolean {\n// \tlet keyData = dotKey.split('.');\n// \tlet objData = obj;\n\t\n// \tfor (let i = 0; i < keyData.length; i++) {\n// \t\tlet key = keyData[i];\n// \t\tif (objData.hasOwnProperty(key)) {\n// \t\t\tobjData = objData[key];\n\t\t\t\n// \t\t\tif (i === keyData.length - 1) {\n// \t\t\t\treturn true;\n// \t\t\t}\n// \t\t}\n// \t\telse {\n// \t\t\treturn false;\n// \t\t}\n// \t}\n// }\n\n// export declare type MongoManagerDotStringFilter<T> = {\n// \t[key: string]: (isDotStringRegExp(T, key) ? any : never);\n// };\n\nexport declare type MongoManagerFilter<T> = {\n\t[P in keyof T]?: T[P] | MongoManagerFilterParamaterOperators<T[P]>;\n};\n\nexport declare type MongoManagerUnsetFilter<T> = {\n\t[P in keyof T]?: number | boolean;\n};\n\nexport declare type MongoManagerIncFilter<T> = {\n\t[P in keyof T]?: number;\n};\n\nexport declare type MongoManagerUpdateFilter<T> = {\n $inc?: MongoManagerIncFilter<T> | Document;\n $set?: MongoManagerFilter<T> | Document;\n $setOnInsert?: MongoManagerFilter<T> | Document;\n $unset?: MongoManagerUnsetFilter<T> | Document;\n};\n\nexport class MongoManager {\n\tprivate _collections: MongoManagerCollection<CollectionDocument>[] = [];\n\tprivate _nodeCache;\n\tprivate _cacheMap: { collections: string[], key: string }[] = [];\n\tprivate _operationInProgress: Map<string, { promise: Promise<any>, invalidatedDuringExecution: boolean }> = new Map();\n\tprivate _heapSize = v8.getHeapStatistics() / numCPUs;\n\tprivate _heapLimit: number;\n\tprivate _serverCollections: (CollectionInfo | Pick<CollectionInfo, 'name' | 'type'>)[] = [];\n\tprivate _serverConfig = null;\n\tprivate _isWorkersEnabled = false;\n\tprivate _isWorkerInstance = false;\n\n\tconstructor(serverConfig) {\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._nodeCache = new NodeCache({ stdTTL: 0, checkperiod: 0 });\n\n\t\tthis._isWorkersEnabled = process.env.IS_WORKERS_ENABLED === 'true';\n\t\tthis._isWorkerInstance = process.env.IS_WORKER_INSTANCE === 'true';\n\t\tthis.setCacheLimit();\n\n\t\tthis.initServerCollections();\n\n\t\tif (this._isWorkersEnabled && this._isWorkerInstance) {\n\t\t\tthis.setupChangeStream();\n\t\t}\n\t}\n\n\tprivate setCacheLimit() {\n\t\tif (this._isWorkersEnabled) {\n\t\t\tthis._heapLimit = this._isWorkerInstance ? this._heapSize * 0.8 : this._heapSize * 0.4;\n\t\t}\n\t\telse {\n\t\t\tthis._heapLimit = this._heapSize * 0.3;\n\t\t}\n\t}\n\n\tasync initServerCollections() {\n\t\tlet collections = await ResolveIOServer.getMainDB().listCollections().toArray();\n\t\tthis._serverCollections = collections;\n\t}\n\n\tgetServerCollections() {\n\t\treturn this._serverCollections;\n\t}\n\n\tregisterCollection(collection: MongoManagerCollection<CollectionDocument>) {\n\t\tif (\n\t\t\tcollection.collectionOptions &&\n\t\t\tcollection.collectionOptions.timeseries &&\n\t\t\tcollection.collectionOptions.timeseries.timeField &&\n\t\t\tthis._serverCollections.some(a => a.name === collection.collectionName && a.type === 'collection')\n\t\t) {\n\t\t\tResolveIOServer.getMainDB()\n\t\t\t\t.dropCollection(collection.collectionName)\n\t\t\t\t.then(() => {\n\t\t\t\t\tthis.createCollection(collection);\n\t\t\t\t});\n\t\t}\n\n\t\tthis._collections.push(collection);\n\t}\n\n\tcreateCollection(collection: MongoManagerCollection<CollectionDocument>) {\n\t\tResolveIOServer.getMainDB().createCollection<CollectionDocument>(collection.collectionName, collection.collectionOptions);\n\t}\n\n\tcollections() {\n\t\treturn this._collections;\n\t}\n\n\tcollection(collectionName: string): MongoManagerCollection<CollectionDocument> | MongoManagerUserCollection<CollectionDocument> {\n\t\treturn this._collections.find(a => a.collectionName === collectionName);\n\t}\n\n\tprivate async delay(ms: number) {\n\t\treturn new Promise(resolve => setTimeout(resolve, ms));\n\t}\n\n\tpublic async find<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {},\n\t\toptions?: FindOptions<T>\n\t): Promise<T[]> {\n\t\tconst cacheKey = this.generateCacheKey([collectionName], 'find', [filter, options]);\n\t\tlet result = this.getFromCache(cacheKey);\n\t\tif (result !== undefined) {\n\t\t\treturn result;\n\t\t}\n\n\t\tif (this._operationInProgress.has(cacheKey)) {\n\t\t\treturn this._operationInProgress.get(cacheKey).promise;\n\t\t}\n\n\t\tconst operation = this.executeFind<T>(collectionName, filter, options, cacheKey);\n\t\tthis._operationInProgress.set(cacheKey, { promise: operation, invalidatedDuringExecution: false });\n\n\t\toperation.finally(() => this._operationInProgress.delete(cacheKey));\n\n\t\treturn operation;\n\t}\n\n\tprivate async executeFind<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>,\n\t\toptions: FindOptions<T> | undefined,\n\t\tcacheKey: string\n\t): Promise<T[]> {\n\t\tlet result;\n\t\tconst collection = ResolveIOServer.getMainDB().collection<T>(collectionName);\n\n\t\tconst monitor = new MonitorMongo('find', collectionName, JSON.stringify([filter, options]));\n\t\tresult = await collection.find(<any>filter, options).toArray();\n\t\tmonitor.finish();\n\t\n\t\tif (!this._operationInProgress.get(cacheKey).invalidatedDuringExecution) {\n\t\t\tthis.addToCache([collectionName], cacheKey, result);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t// FindOne Operation\n\tpublic async findOne<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> | MongoManagerFilterOperators<T> = {},\n\t\toptions?: FindOptions<T>\n\t): Promise<T> {\n\t\tconst cacheKey = this.generateCacheKey([collectionName], 'findOne', [filter, options]);\n\t\tlet result = this.getFromCache(cacheKey);\n\t\tif (result !== undefined) {\n\t\t\treturn result;\n\t\t}\n\n\t\tif (this._operationInProgress.has(cacheKey)) {\n\t\t\treturn this._operationInProgress.get(cacheKey).promise;\n\t\t}\n\n\t\tconst operation = this.executeFindOne<T>(collectionName, filter, options, cacheKey);\n\t\tthis._operationInProgress.set(cacheKey, { promise: operation, invalidatedDuringExecution: false });\n\n\t\toperation.finally(() => this._operationInProgress.delete(cacheKey));\n\n\t\treturn operation;\n\t}\n\n\tprivate async executeFindOne<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> | MongoManagerFilterOperators<T>,\n\t\toptions: FindOptions<T> | undefined,\n\t\tcacheKey: string\n\t): Promise<T> {\n\t\tlet result;\n\t\tconst collection = ResolveIOServer.getMainDB().collection<T>(collectionName);\n\n\t\tconst monitor = new MonitorMongo('findOne', collectionName, JSON.stringify([filter, options]));\n\t\tresult = await collection.findOne(<any>filter, options);\n\t\tmonitor.finish();\n\t\n\t\tif (!this._operationInProgress.get(cacheKey).invalidatedDuringExecution) {\n\t\t\tthis.addToCache([collectionName], cacheKey, result);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t// Aggregate Operation\n\tpublic async aggregate<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tpipeline: any[],\n\t\toptions?: AggregateOptions\n\t): Promise<any[]> {\n\t\tconst collections = [collectionName, ...pipeline.flatMap(stage => stage.$lookup?.from ? [stage.$lookup.from] : [])];\n\t\tconst cacheKey = this.generateCacheKey(collections, 'aggregate', [pipeline, options]);\n\t\tlet result = this.getFromCache(cacheKey);\n\t\tif (result !== undefined) {\n\t\t\treturn result;\n\t\t}\n\n\t\tif (this._operationInProgress.has(cacheKey)) {\n\t\t\treturn this._operationInProgress.get(cacheKey).promise;\n\t\t}\n\n\t\tconst operation = this.executeAggregate<T>(collectionName, pipeline, options, cacheKey, collections);\n\t\tthis._operationInProgress.set(cacheKey, { promise: operation, invalidatedDuringExecution: false });\n\n\t\toperation.finally(() => this._operationInProgress.delete(cacheKey));\n\n\t\treturn operation;\n\t}\n\n\tprivate async executeAggregate<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tpipeline: any[],\n\t\toptions: AggregateOptions | undefined,\n\t\tcacheKey: string,\n\t\tcollections: string[]\n\t): Promise<any[]> {\n\t\tlet result;\n\t\tconst collection = ResolveIOServer.getMainDB().collection<T>(collectionName);\n\n\t\tconst monitor = new MonitorMongo('aggregate', collectionName, JSON.stringify([pipeline, options]));\n\t\tresult = await collection.aggregate(pipeline, options).toArray();\n\t\tmonitor.finish();\n\n\t\tif (!this._operationInProgress.get(cacheKey).invalidatedDuringExecution) {\n\t\t\tthis.addToCache(collections, cacheKey, result);\n\t\t}\n\t\t\n\t\treturn result;\n\t}\n\n\tpublic async countDocuments<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> | MongoManagerFilterOperators<T> = {},\n\t\toptions?: CountDocumentsOptions\n\t): Promise<number> {\n\t\tconst cacheKey = this.generateCacheKey([collectionName], 'countDocuments', [filter, options]);\n\t\tlet result = this.getFromCache(cacheKey);\n\t\tif (result !== undefined) {\n\t\t\treturn result;\n\t\t}\n\n\t\tif (this._operationInProgress.has(cacheKey)) {\n\t\t\treturn this._operationInProgress.get(cacheKey).promise;\n\t\t}\n\n\t\tconst operation = this.executeCountDocuments<T>(collectionName, filter, options, cacheKey);\n\t\tthis._operationInProgress.set(cacheKey, { promise: operation, invalidatedDuringExecution: false });\n\n\t\toperation.finally(() => this._operationInProgress.delete(cacheKey));\n\n\t\treturn operation;\n\t}\n\n\tprivate async executeCountDocuments<T extends CollectionDocument>(\n\t\tcollectionName: string,\n\t\tfilter: MongoManagerFilter<T> | MongoManagerFilterOperators<T>,\n\t\toptions: CountDocumentsOptions,\n\t\tcacheKey: string\n\t): Promise<number> {\n\t\tlet result;\n\t\tconst collection = ResolveIOServer.getMainDB().collection<T>(collectionName);\n\n\t\tconst monitor = new MonitorMongo('countDocuments', collectionName, JSON.stringify([filter, options]));\n\t\tresult = await collection.countDocuments(<any>filter, options);\n\t\tmonitor.finish();\n\t\n\t\tif (!this._operationInProgress.get(cacheKey).invalidatedDuringExecution) {\n\t\t\tthis.addToCache([collectionName], cacheKey, result);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t// Cache and Invalidation Setup\n\tprivate generateCacheKey(collections: string[], functionName: string, args: any[]): string {\n\t\tconst keyString = JSON.stringify({ collections, functionName, args });\n\t\treturn crypto.createHash('sha256').update(keyString).digest('hex');\n\t}\n\n\tprivate getFromCache(cacheKey: string): any | undefined {\n\t\ttry {\n\t\t\tconst cachedData = this._nodeCache.get(cacheKey);\n\t\t\tif (cachedData) {\n\t\t\t\treturn JSON.parse(cachedData, dateReviver);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis._nodeCache.del(cacheKey);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate addToCache(collections: string[], cacheKey: string, data: any) {\n\t\tif (getBinarySize(JSON.stringify(data)) < 1000000) {\n\t\t\tlet nodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\tlet deleteCount = 0;\n\t\t\t\tconst keys = this._nodeCache.keys();\n\n\t\t\t\tfor (const key of keys) {\n\t\t\t\t\tthis._nodeCache.del(key);\n\t\t\t\t\tdeleteCount += 1;\n\n\t\t\t\t\tnodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\t\t\tif (nodeCacheSize < this._heapLimit * 0.75) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconsole.log('Query Cache: ' + 'Too Big, - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);\n\t\t\t}\n\t\t\t\n\t\t\tthis._nodeCache.set(cacheKey, JSON.stringify(data));\n\t\t\tthis._cacheMap.push({ collections, key: cacheKey });\n\t\t}\n\t}\n\n\tpublic invalidateQueryCache(collection: string) {\n\t\tconst collectionCacheMap = this._cacheMap.filter(a => a.collections.includes(collection));\n\n\t\tfor (const cacheMap of collectionCacheMap) {\n\t\t\tthis._nodeCache.del(cacheMap.key);\n\t\t\t\n\t\t\tif (this._operationInProgress.has(cacheMap.key)) {\n\t\t\t\tthis._operationInProgress.get(cacheMap.key).invalidatedDuringExecution = true;\n\t\t\t}\n\t\t}\n\n\t\tthis._cacheMap = this._cacheMap.filter(a => !a.collections.includes(collection));\n\t}\n\n\tprivate setupChangeStream() {\n\t\tconst db = ResolveIOServer.getMainDB();\n\n\t\tconst pipeline = [\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t$and: [\n\t\t\t\t\t\t{'ns.coll': { $nin: ['logs', 'log-method-latencies', 'log-subscriptions'] }},\n\t\t\t\t\t\t{'ns.coll': { $not: /.*\\.versions$/ }},\n\t\t\t\t\t\t{'ns.coll': { $not: /^monitor-/ }},\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t\tconst changeStream = db.watch(pipeline);\n\n\t\tchangeStream.on('change', async (change: ChangeStreamDocument) => {\n\t\t\tif (change['ns'] && change['ns'].coll) {\n\t\t\t\tconst collectionName = change['ns'].coll;\n\t\t\t\tif (this.collection(collectionName)) {\n\t\t\t\t\tthis.invalidateQueryCache(collectionName);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tchangeStream.on('error', err => {\n\t\t\tconsole.log(new Date(), 'Mongo change stream error. Restart...');\n\t\t\tchangeStream.close();\n\t\t\tsetTimeout(() => this.setupChangeStream(), 5000);\n\t\t});\n\n\t\tchangeStream.on('close', () => {\n\t\t\tconsole.log(new Date(), 'Mongo change stream closed. Restarting...');\n\t\t\tsetTimeout(() => this.setupChangeStream(), 5000);\n\t\t});\n\t}\n}\n\nexport class MongoManagerModel<T extends CollectionDocument> {\n\tcollection_main: MongoManagerCollection<T> | MongoManagerUserCollection<T> = null;\n\tcollection_version: MongoManagerCollection<T> | MongoManagerUserCollection<T> = null;\n\n\tconstructor(options: MongoManagerCollectionOptions) {\n\t\tif (options.collectionName === 'users') {\n\t\t\tthis.collection_main = new MongoManagerUserCollection<T>(options);\n\t\t}\n\t\telse {\n\t\t\tthis.collection_main = new MongoManagerCollection<T>(options);\n\t\t}\n\n\t\tif (options.useVersionCollection) {\n\t\t\tthis.collection_main.useVersions = true;\n\t\t\t\n\t\t\tlet versionSchema = deepCopy(options.schema);\n\t\t\tversionSchema._id.type = 'Object';\n\t\t\tversionSchema._id.blackbox = true;\n\n\t\t\tlet versionOptions: MongoManagerCollectionOptions = {\n\t\t\t\tcollectionName: options.collectionName + '.versions',\n\t\t\t\tschema: versionSchema,\n\t\t\t\tuseVersionCollection: false,\n\t\t\t\tuseReportBuilder: false,\n\t\t\t\treportBuilderLookupTables: [],\n\t\t\t\ttimestamps: true,\n\t\t\t\tcreateLogs: false,\n\t\t\t\tcheckSchema: false,\n\t\t\t\tcollectionOptions: null\n\t\t\t};\n\n\t\t\tif (options.collectionName === 'users') {\t\n\t\t\t\tthis.collection_version = new MongoManagerUserCollection<T>(versionOptions);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.collection_version = new MongoManagerCollection<T>(versionOptions);\n\t\t\t}\n\n\t\t\tthis.collection_version.createIndex({'_id._id': 1, '_id.__v': 1});\n\t\t\tthis.collection_main.versionCollection = options.collectionName + '.versions';\n\t\t}\n\t}\n}\n\nexport interface MongoManagerCollectionOptions {\n\tcollectionName: string;\n\tschema: object;\n\tuseVersionCollection: boolean;\n\tuseReportBuilder: boolean;\n\treportBuilderLookupTables: LookupTables[]\n\ttimestamps: boolean;\n\tcreateLogs: boolean;\n\tcheckSchema: boolean;\n\tcollectionOptions: CreateCollectionOptions;\n}\n\nexport class MongoManagerCollection<T extends CollectionDocument> {\n\tcollectionName = '';\n\tcheckSchema = false;\n\tsimplschema = null;\n\trbSchema = null;\n\ttimestamps = false;\n\tuseVersions = false;\n\tversionCollection = '';\n\tcreateLogs = true;\n\tuseRB = false;\n\tcollectionOptions: CreateCollectionOptions;\n\t\n\tconstructor(options: MongoManagerCollectionOptions) {\n\t\tthis.collectionName = options.collectionName;\n\t\tthis.simplschema = new SimpleSchema(options.schema);\n\t\tthis.timestamps = options.timestamps;\n\t\tthis.createLogs = options.createLogs;\n\t\tthis.checkSchema = options.checkSchema;\n\t\tthis.collectionOptions = options.collectionOptions;\n\n\t\tif (options.useReportBuilder) {\n\t\t\tthis.useRB = true;\n\t\t\tlet schemaCopy = deepCopy(options.schema);\n\t\t\tlet rbSchema = buildRbLookups(options.reportBuilderLookupTables, schemaCopy, []);\n\t\t\tthis.rbSchema = buildRbSchema(rbSchema);\n\t\t}\n\n\t\tlet interval = setInterval(() => {\n\t\t\tif (ResolveIOServer && ResolveIOServer.getMainServer() && ResolveIOServer.getMongoManager() && ResolveIOServer.getMongoManager().getServerCollections().length) {\n\t\t\t\tResolveIOServer.getMongoManager().registerCollection(this);\n\t\t\t\tclearInterval(interval);\n\t\t\t}\n\t\t}, 1);\n\t}\n\n\tprivate static indexQueue = async.queue(async (task, callback) => {\n\t\tconst { action, collection, specs, options } = task;\n\t\tconst dbCollection = ResolveIOServer.getMainDB().collection(collection.collectionName, collection.collectionOptions);\n\t\n\t\tif (!dbCollection) {\n\t\t\treturn callback(new Error(`Collection ${collection.collectionName} not found`));\n\t\t}\n\t\n\t\tlet monitor = new MonitorMongo(action, collection.collectionName, JSON.stringify([specs, options]));\n\t\n\t\ttry {\n\t\t\t// Try creating the index, will auto-skip if already checked in createIndex/createIndexes\n\t\t\tconst result = await dbCollection[action](...specs, options);\n\t\t\tmonitor.finish();\n\t\t\tcallback(null, result);\n\t\t} catch (err) {\n\t\t\t// Handle any specific errors related to index creation\n\t\t\tif (err.code === 85 || err.message.includes('IndexOptionsConflict')) {\n\t\t\t\ttry {\n\t\t\t\t\tconst existingIndexName = collection.extractIndexNameFromError(err.message);\n\t\t\t\t\tif (existingIndexName) {\n\t\t\t\t\t\tawait dbCollection.dropIndex(existingIndexName);\n\t\t\t\t\t\tconst result = await dbCollection[action](...specs, options);\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tcallback(null, result);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} catch (innerError) {\n\t\t\t\t\tcallback(innerError);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmonitor.finish();\n\t\t\tcallback(err);\n\t\t}\n\t}, 1);\n\n // Method to extract index name from error message\n extractIndexNameFromError(errorMessage) {\n\t\tlet regexPattern = /Index already exists with a different name: (\\S+)/;\n\t\tlet matches = errorMessage.match(regexPattern);\n\t\n\t\tif (!matches || matches.length <= 1) {\n\t\t\t// If the first pattern doesn't match, try the second pattern\n\t\t\tregexPattern = /existing index:.*name: \"([^\"]+)\"/;\n\t\t\tmatches = errorMessage.match(regexPattern);\n\t\t}\n\t\n\t\treturn matches && matches.length > 1 ? matches[1] : null;\n\t}\t\n\n\taggregate(pipeline: object[], options?: AggregateOptions, skipCache = false) : Promise<any[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tif (!skipCache) {\n\t\t\t\tResolveIOServer.getMongoManager().aggregate(this.collectionName, pipeline, options).then(res => {\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet monitor = new MonitorMongo('aggregate', this.collectionName, JSON.stringify([pipeline, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).aggregate(pipeline, options).toArray().then(res => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Aggregate', this.collectionName, pipeline, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tasync aggregateCount(pipeline: object[], options?: AggregateOptions) : Promise<number> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('aggregateCount', this.collectionName, JSON.stringify([pipeline, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).aggregate(pipeline, options).toArray().then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res.length);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Aggregate', this.collectionName, pipeline, options, err);\n\t\t\t\treject(0);\n\t\t\t});\n\t\t});\n\t}\n\n\taggregateCursor(pipeline: object[], options?: AggregateOptions): AggregationCursor {\n\t\tlet monitor = new MonitorMongo('aggregateCursor', this.collectionName, JSON.stringify([pipeline, options]));\n\t\tlet cursor = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).aggregate(pipeline, options);\n\t\tcursor.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn cursor;\n\t}\n\n\taggregateStream(pipeline: object[], options?: AggregateOptions, streamOptions?: CursorStreamOptions) {\n\t\tlet monitor = new MonitorMongo('aggregateStream', this.collectionName, JSON.stringify([pipeline, options, streamOptions]));\n\t\tlet stream = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).aggregate(pipeline, options).stream(streamOptions);\n\t\tstream.on('end', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t})\n\t\t.on('error', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t})\n\t\t.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn stream;\n\t}\n\n\t// bulkWrite(operations: AnyBulkWriteOperation<T>[], options: BulkWriteOptions): Promise<BulkWriteResult> {\n\tasync bulkWrite(\n\t\toperations: any[],\n\t\toptions?: BulkWriteOptions,\n\t\tbypassLogs = false,\n\t\tbypassCheckSchema = false,\n\t\tbypassVersions = false\n\t): Promise<BulkWriteResult> {\n\t\tif (!operations.length) {\n\t\t\treturn null;\n\t\t}\n\t\n\t\tconst bulkOps = [];\n\t\tconst logs = [];\n\t\tconst modifiedIds = new Set<string>();\n\t\n\t\tconst additionalFilters = [];\n\t\tconst fieldNamesSet = new Set<string>();\n\t\n\t\t// Prepare bulk operations and collect modified IDs\n\t\tfor (let opIndex = 0; opIndex < operations.length; opIndex++) {\n\t\t\tconst op = operations[opIndex];\n\t\t\tconst opType = Object.keys(op)[0];\n\t\t\tconst doc = op[opType];\n\t\n\t\t\tif (opType === 'insertOne') {\n\t\t\t\t// Handle insertOne\n\t\t\t\tif (!doc.document._id) {\n\t\t\t\t\tdoc.document._id = objectIdHexString();\n\t\t\t\t}\n\t\t\t\tif (this.useVersions && doc.document.__v === undefined) {\n\t\t\t\t\tdoc.document.__v = 0;\n\t\t\t\t}\n\t\t\t\tif (this.timestamps) {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdoc.document.createdAt = doc.document.createdAt || date;\n\t\t\t\t\tdoc.document.updatedAt = doc.document.updatedAt || date;\n\t\t\t\t}\n\t\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\tif (!validation.validate(doc.document)) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Schema validation failed for insertOne: ${JSON.stringify(validation.validationErrors())}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbulkOps.push(op);\n\t\n\t\t\t\t// Collect logs if necessary\n\t\t\t\tif (!bypassLogs && this.createLogs) {\n\t\t\t\t\tlogs.push({\n\t\t\t\t\t\tinsertOne: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: doc.document._id,\n\t\t\t\t\t\t\t\tpayload:\n\t\t\t\t\t\t\t\t\tgetBinarySize(JSON.stringify([op, options])) < 200000\n\t\t\t\t\t\t\t\t\t\t? JSON.stringify([op, options], null, 2)\n\t\t\t\t\t\t\t\t\t\t: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: opType,\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\n\t\t\t\t// Track inserted IDs for versioning\n\t\t\t\tif (!bypassVersions && this.useVersions) {\n\t\t\t\t\tmodifiedIds.add(doc.document._id);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (opType === 'updateOne' || opType === 'replaceOne') {\n\t\t\t\t// Handle updateOne and replaceOne\n\t\t\t\tif (opType === 'updateOne') {\n\t\t\t\t\tif (!doc.update.$set) doc.update.$set = {};\n\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\tdoc.update.$set.updatedAt = new Date();\n\t\t\t\t\t}\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tif (!doc.update.$inc) doc.update.$inc = {};\n\t\t\t\t\t\tdoc.update.$inc.__v = 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (doc.upsert) {\n\t\t\t\t\t\tif (!doc.update.$setOnInsert) doc.update.$setOnInsert = {};\n\t\t\t\t\t\tif (!doc.update.$setOnInsert._id) doc.update.$setOnInsert._id = objectIdHexString();\n\t\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\t\tdoc.update.$setOnInsert.createdAt = new Date();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\t\tdoc.update.$setOnInsert.__v = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\t\tif (!validation.validate(doc.update, { modifier: true })) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Schema validation failed for updateOne: ${JSON.stringify(validation.validationErrors())}`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (opType === 'replaceOne') {\n\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\tdoc.replacement.updatedAt = new Date();\n\t\t\t\t\t\tif (doc.upsert && !doc.replacement.createdAt) {\n\t\t\t\t\t\t\tdoc.replacement.createdAt = new Date();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tdoc.replacement.__v = doc.replacement.__v !== undefined ? doc.replacement.__v + 1 : 0;\n\t\t\t\t\t}\n\t\t\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\t\tif (!validation.validate(doc.replacement)) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Schema validation failed for replaceOne: ${JSON.stringify(validation.validationErrors())}`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbulkOps.push(op);\n\t\n\t\t\t\t// Collect logs if necessary\n\t\t\t\tif (!bypassLogs && this.createLogs) {\n\t\t\t\t\tlet id_document = '';\n\t\t\t\t\tif (doc.filter && doc.filter._id) {\n\t\t\t\t\t\tid_document = doc.filter._id;\n\t\t\t\t\t\t// Track modified IDs for versioning\n\t\t\t\t\t\tif (!bypassVersions && this.useVersions) {\n\t\t\t\t\t\t\tmodifiedIds.add(doc.filter._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Collect filters for additional querying\n\t\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: logs.length, isSingle: true });\n\t\t\t\t\t\t// Extract field names from filter\n\t\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tlogs.push({\n\t\t\t\t\t\tinsertOne: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: id_document,\n\t\t\t\t\t\t\t\tpayload:\n\t\t\t\t\t\t\t\t\tgetBinarySize(JSON.stringify([op, options])) < 200000\n\t\t\t\t\t\t\t\t\t\t? JSON.stringify([op, options], null, 2)\n\t\t\t\t\t\t\t\t\t\t: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: opType,\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// Even if not logging, we need to track modified IDs for versioning\n\t\t\t\t\tif (!bypassVersions && doc.filter && doc.filter._id && this.useVersions) {\n\t\t\t\t\t\tmodifiedIds.add(doc.filter._id);\n\t\t\t\t\t}\n\t\t\t\t\telse if (!bypassVersions && this.useVersions) {\n\t\t\t\t\t\t// Need to collect filters to fetch _id later\n\t\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: null, isSingle: true });\n\t\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (opType === 'updateMany') {\n\t\t\t\t// Handle updateMany\n\t\t\t\tif (!doc.update.$set) doc.update.$set = {};\n\t\t\t\tif (this.timestamps) {\n\t\t\t\t\tdoc.update.$set.updatedAt = new Date();\n\t\t\t\t}\n\t\t\t\tif (this.useVersions) {\n\t\t\t\t\tif (!doc.update.$inc) doc.update.$inc = {};\n\t\t\t\t\tdoc.update.$inc.__v = 1;\n\t\t\t\t}\n\t\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\tif (!validation.validate(doc.update, { modifier: true })) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Schema validation failed for updateMany: ${JSON.stringify(validation.validationErrors())}`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbulkOps.push(op);\n\t\n\t\t\t\t// Collect logs if necessary\n\t\t\t\tif (!bypassLogs && this.createLogs) {\n\t\t\t\t\t// We need to fetch the affected documents to get their _id\n\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: logs.length, isUpdateMany: true });\n\t\t\t\t\t// Extract field names from filter\n\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\n\t\t\t\t\tlogs.push({\n\t\t\t\t\t\tinsertMany: [] // We will populate this after fetching documents\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (!bypassVersions && this.useVersions) {\n\t\t\t\t\t// Need to collect filters to fetch _id for versioning\n\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: null, isUpdateMany: true });\n\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (opType === 'deleteOne' || opType === 'deleteMany') {\n\t\t\t\t// Handle deleteOne and deleteMany\n\t\t\t\tbulkOps.push(op);\n\t\n\t\t\t\t// Collect logs if necessary\n\t\t\t\tif (!bypassLogs && this.createLogs) {\n\t\t\t\t\tlet id_document = '';\n\t\t\t\t\tif (doc.filter && doc.filter._id) {\n\t\t\t\t\t\tid_document = doc.filter._id;\n\t\t\t\t\t\t// Track modified IDs for versioning\n\t\t\t\t\t\tif (!bypassVersions && this.useVersions) {\n\t\t\t\t\t\t\tmodifiedIds.add(doc.filter._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Collect filters for additional querying\n\t\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: logs.length, isDeleteMany: opType === 'deleteMany' });\n\t\t\t\t\t\t// Extract field names from filter\n\t\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tlogs.push({\n\t\t\t\t\t\tinsertOne: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: id_document,\n\t\t\t\t\t\t\t\tpayload:\n\t\t\t\t\t\t\t\t\tgetBinarySize(JSON.stringify([op, options])) < 200000\n\t\t\t\t\t\t\t\t\t\t? JSON.stringify([op, options], null, 2)\n\t\t\t\t\t\t\t\t\t\t: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: opType,\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (!bypassVersions && this.useVersions) {\n\t\t\t\t\tif (doc.filter && doc.filter._id) {\n\t\t\t\t\t\tmodifiedIds.add(doc.filter._id);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Need to collect filters to fetch _id for versioning\n\t\t\t\t\t\tadditionalFilters.push({ filter: doc.filter, opIndex: null, isDeleteMany: opType === 'deleteMany' });\n\t\t\t\t\t\tthis.extractFieldNames(doc.filter, fieldNamesSet);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new Error(`Unsupported operation type: ${opType}`);\n\t\t\t}\n\t\t}\n\t\n\t\ttry {\n\t\t\t// Fetch necessary fields for logs and versioning where required\n\t\t\tif (!bypassVersions && additionalFilters.length) {\n\t\t\t\t// Combine all filters into one query using $or\n\t\t\t\tconst combinedFilter = {\n\t\t\t\t\t$or: additionalFilters.map(item => item.filter)\n\t\t\t\t};\n\t\n\t\t\t\t// Build the projection object with necessary fields\n\t\t\t\tconst projection: any = { _id: 1 };\n\t\t\t\tfieldNamesSet.forEach(field => {\n\t\t\t\t\tprojection[field] = 1;\n\t\t\t\t});\n\t\n\t\t\t\t// Fetch matching documents with necessary fields\n\t\t\t\tconst cursor = ResolveIOServer.getMainDB()\n\t\t\t\t\t.collection<T>(this.collectionName)\n\t\t\t\t\t.find(combinedFilter, { projection });\n\t\n\t\t\t\tconst docs = await cursor.toArray();\n\t\n\t\t\t\t// Map documents to their filters\n\t\t\t\tfor (const doc of docs) {\n\t\t\t\t\t// For each filter, check if it matches this document\n\t\t\t\t\tfor (const item of additionalFilters) {\n\t\t\t\t\t\tif (sift(item.filter)(doc)) {\n\t\t\t\t\t\t\tif (item.opIndex !== null) {\n\t\t\t\t\t\t\t\t// For logs\n\t\t\t\t\t\t\t\tif (item.isUpdateMany || item.isDeleteMany) {\n\t\t\t\t\t\t\t\t\t// For updateMany and deleteMany, we collect multiple documents\n\t\t\t\t\t\t\t\t\tif (!logs[item.opIndex].insertMany) {\n\t\t\t\t\t\t\t\t\t\tlogs[item.opIndex].insertMany = [];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tlogs[item.opIndex].insertMany.push({\n\t\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\t\t\t\t\tpayload:\n\t\t\t\t\t\t\t\t\t\t\tgetBinarySize(JSON.stringify([operations[item.opIndex], options])) < 200000\n\t\t\t\t\t\t\t\t\t\t\t\t? JSON.stringify([operations[item.opIndex], options], null, 2)\n\t\t\t\t\t\t\t\t\t\t\t\t: 'Too Big',\n\t\t\t\t\t\t\t\t\t\tmethod: operations[item.opIndex] ? Object.keys(operations[item.opIndex])[0] : '',\n\t\t\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if (item.isSingle) {\n\t\t\t\t\t\t\t\t\t// For updateOne and deleteOne without _id in filter\n\t\t\t\t\t\t\t\t\tlogs[item.opIndex].insertOne.document.id_document = doc._id;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// For versioning\n\t\t\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\t\t\tmodifiedIds.add(<string>doc._id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t// Perform the bulkWrite operations\n\t\t\tconst mainResult = await ResolveIOServer.getMainDB()\n\t\t\t\t.collection<T>(this.collectionName)\n\t\t\t\t.bulkWrite(bulkOps, options);\n\t\n\t\t\t// Versioning using aggregation pipeline\n\t\t\tif (!bypassVersions && this.useVersions && modifiedIds.size > 0) {\n\t\t\t\tconst modifiedIdsArray = Array.from(modifiedIds);\n\t\n\t\t\t\t// Create versions using aggregation\n\t\t\t\tResolveIOServer.getMainDB()\n\t\t\t\t\t.collection<T>(this.collectionName)\n\t\t\t\t\t.aggregate([\n\t\t\t\t\t\t{ $match: { _id: { $in: modifiedIdsArray } } },\n\t\t\t\t\t\t{ $addFields: { '_id': { _id: '$_id', __v: '$__v' } } },\n\t\t\t\t\t\t{ $project: { '__v': 0 } },\n\t\t\t\t\t\t{ $merge: {\n\t\t\t\t\t\t\tinto: this.versionCollection,\n\t\t\t\t\t\t\ton: '_id',\n\t\t\t\t\t\t\twhenMatched: 'fail',\n\t\t\t\t\t\t\twhenNotMatched: 'insert'\n\t\t\t\t\t\t}}\n\t\t\t\t\t])\n\t\t\t\t\t.toArray();\n\t\n\t\t\t\t// Delete old versions without loops\n\t\t\t\tconst oldVersions = await ResolveIOServer.getMainDB()\n\t\t\t\t\t.collection<T>(this.versionCollection)\n\t\t\t\t\t.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t'_id._id': { $in: modifiedIdsArray }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$sort: {\n\t\t\t\t\t\t\t\t'_id._id': 1,\n\t\t\t\t\t\t\t\t'_id.__v': -1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: '$_id._id',\n\t\t\t\t\t\t\t\tdocs: { $push: '$_id' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\t\t\tdocsToDelete: {\n\t\t\t\t\t\t\t\t\t$slice: ['$docs', 5, { $size: '$docs' }]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ $unwind: '$docsToDelete' },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$replaceRoot: { newRoot: '$docsToDelete' }\n\t\t\t\t\t\t}\n\t\t\t\t\t])\n\t\t\t\t\t.toArray();\n\t\n\t\t\t\tif (oldVersions.length > 0) {\n\t\t\t\t\tResolveIOServer.getMainDB()\n\t\t\t\t\t\t.collection<T>(this.versionCollection)\n\t\t\t\t\t\t.deleteMany(<any>{ _id: { $in: oldVersions } });\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t// Perform logging if necessary\n\t\t\tif (!bypassLogs && logs.length) {\n\t\t\t\t// For logs with insertMany (updateMany, deleteMany), we need to expand them\n\t\t\t\tconst expandedLogs = [];\n\t\t\t\tfor (const log of logs) {\n\t\t\t\t\tif (log.insertOne) {\n\t\t\t\t\t\texpandedLogs.push(log);\n\t\t\t\t\t}\n\t\t\t\t\telse if (log.insertMany) {\n\t\t\t\t\t\tfor (const doc of log.insertMany) {\n\t\t\t\t\t\t\texpandedLogs.push({\n\t\t\t\t\t\t\t\tinsertOne: {\n\t\t\t\t\t\t\t\t\tdocument: doc\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\n\t\t\t\tif (expandedLogs.length) {\n\t\t\t\t\tLogs.bulkWrite(expandedLogs, { ordered: false });\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t// Invalidate cache\n\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\n\t\t\treturn mainResult;\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error('Error in bulkWrite:', err);\n\t\t\tthrow err;\n\t\t}\n\t}\n\t\n\t// Helper function to extract field names from filters\n\tprivate extractFieldNames(filter: any, fieldNamesSet: Set<string>, prefix = '') {\n\t\tif (typeof filter !== 'object' || filter == null) {\n\t\t\treturn;\n\t\t}\n\t\n\t\tfor (const key in filter) {\n\t\t\tconst value = filter[key];\n\t\t\tif (key.startsWith('$')) {\n\t\t\t\t// Logical operator ($and, $or, etc.)\n\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\tvalue.forEach(subFilter => this.extractFieldNames(subFilter, fieldNamesSet, prefix));\n\t\t\t\t}\n\t\t\t\telse if (typeof value === 'object') {\n\t\t\t\t\tthis.extractFieldNames(value, fieldNamesSet, prefix);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconst fullPath = prefix ? `${prefix}.${key}` : key;\n\t\t\t\tif (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n\t\t\t\t\t// May contain operators like $eq, $gt, etc.\n\t\t\t\t\tfieldNamesSet.add(fullPath);\n\t\t\t\t\tthis.extractFieldNames(value, fieldNamesSet, fullPath);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfieldNamesSet.add(fullPath);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tcountDocuments(\n\t\tfilter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {},\n\t\toptions?: CountDocumentsOptions,\n\t\tskipCache = false\n\t): Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\ttry {\n\t\t\t\t// Check if the filter is empty\n\t\t\t\tconst isUnfiltered = Object.keys(filter).length === 0;\n\t\n\t\t\t\tif (isUnfiltered) {\n\t\t\t\t\t// Use collection stats for an unfiltered count\n\t\t\t\t\tconst res = await ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).estimatedDocumentCount(options);\n\t\t\t\t\tresolve(res);\n\t\t\t\t}\n\t\t\t\telse if (!skipCache) {\n\t\t\t\t\t// Use cached count if skipCache is false\n\t\t\t\t\tResolveIOServer.getMongoManager().countDocuments(this.collectionName, filter, options).then(\n\t\t\t\t\t\tres => resolve(res),\n\t\t\t\t\t\terr => reject(err)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// Fallback to direct countDocuments call with monitoring if skipCache is true\n\t\t\t\t\tlet monitor = new MonitorMongo('countDocuments', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).countDocuments(<any>filter, options).then(\n\t\t\t\t\t\tres => {\n\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\tresolve(res);\n\t\t\t\t\t\t},\n\t\t\t\t\t\terr => {\n\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Error Count Documents', this.collectionName, filter, options, err);\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconsole.log(new Date(), 'Error Count Documents (Stats)', this.collectionName, filter, options, err);\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t}\n\n\t//Helper Function (1 or Many) - Not Real Mongo Function\n\tcreate(f_docs: T | T[], options?: InsertOneOptions | BulkWriteOptions): Promise<T | T[]> {\n\t\tif (!Array.isArray(f_docs)) {\n\t\t\treturn this.insertOne(f_docs, <InsertOneOptions>options);\n\t\t}\n\t\telse if (f_docs.length === 1) {\n\t\t\treturn this.insertOne(f_docs[0], <InsertOneOptions>options);\n\t\t}\n\n\t\treturn this.insertMany(f_docs, <BulkWriteOptions>options);\n\t}\n\n\tcreateIndex(fieldOrSpec: any, options?: CreateIndexesOptions): Promise<string> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\ttry {\n\t\t\t\t// Check if index already exists based on the key\n\t\t\t\tconst dbCollection = ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions);\n\t\t\t\tconst existingIndexes = await dbCollection.indexes();\n\t\n\t\t\t\t// Check if an index with the same key already exists\n\t\t\t\tconst indexExists = existingIndexes.some(index => \n\t\t\t\t\tJSON.stringify(index.key) === JSON.stringify(fieldOrSpec)\n\t\t\t\t);\n\t\n\t\t\t\tif (indexExists) {\n\t\t\t\t\treturn resolve('Index already exists'); // Skip creation if index exists\n\t\t\t\t}\n\t\n\t\t\t\t// If index doesn't exist, push it to the queue\n\t\t\t\tMongoManagerCollection.indexQueue.push({\n\t\t\t\t\taction: 'createIndex',\n\t\t\t\t\tcollection: this,\n\t\t\t\t\tspecs: [fieldOrSpec],\n\t\t\t\t\toptions: options\n\t\t\t\t}, (err, result) => {\n\t\t\t\t\tif (err) reject(err);\n\t\t\t\t\telse resolve(result);\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t}\n\t\n\tcreateIndexes(indexSpecs: IndexDescription[], options?: CreateIndexesOptions): Promise<string[]> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\ttry {\n\t\t\t\tconst dbCollection = ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions);\n\t\t\t\tconst existingIndexes = await dbCollection.indexes();\n\t\n\t\t\t\t// Filter out indexes that already exist based on the key\n\t\t\t\tconst indexesToCreate = indexSpecs.filter(indexSpec => \n\t\t\t\t\t!existingIndexes.some(existingIndex => \n\t\t\t\t\t\tJSON.stringify(existingIndex.key) === JSON.stringify(indexSpec.key)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\n\t\t\t\t// If no new indexes to create, resolve early\n\t\t\t\tif (indexesToCreate.length === 0) {\n\t\t\t\t\treturn resolve(['All indexes already exist']);\n\t\t\t\t}\n\t\n\t\t\t\t// Push only new indexes to the queue\n\t\t\t\tMongoManagerCollection.indexQueue.push({\n\t\t\t\t\taction: 'createIndexes',\n\t\t\t\t\tcollection: this,\n\t\t\t\t\tspecs: [indexesToCreate],\n\t\t\t\t\toptions: options\n\t\t\t\t}, (err, result) => {\n\t\t\t\t\tif (err) reject(err);\n\t\t\t\t\telse resolve(result);\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\treject(err);\n\t\t\t}\n\t\t});\n\t}\n\t\n\n\tdeleteMany(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: DeleteOptions, bypassLogs = false): Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\tlet docs = await this.find(filter);\n\n\t\t\t\tfor (let i = 0; i < docs.length; i++) {\n\t\t\t\t\tlet doc = docs[i];\n\t\t\t\t\n\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',\n\t\t\t\t\t\tmethod: 'deleteMany',\n\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\troute: ''\n\t\t\t\t\t});\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 1}}]});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('deleteMany', this.collectionName, JSON.stringify([filter, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).deleteMany(<any>filter, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\tresolve(res.deletedCount);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Delete Many', this.collectionName, filter, options, err);\n\t\t\t\treject(err)\n\t\t\t});\n\t\t});\n\t}\n\n\tdeleteOne(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOneAndDeleteOptions, bypassLogs = false): Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\tlet monitor = new MonitorMongo('findOneAndDelete', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndDelete(<any>filter, options).then(async returnVal => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tlet doc = returnVal;\n\n\t\t\t\t\tif (doc) {\n\t\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'deleteOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\t\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 1}}]});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\n\t\t\t\t\t\tresolve(1);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tresolve(0);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Find One And Delete', this.collectionName, filter, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet monitor = new MonitorMongo('deleteOne', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).deleteOne(<any>filter, options).then(res => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\tresolve(res.deletedCount);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Delete One', this.collectionName, filter, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\t\t\t\n\t\t});\n\t}\n\n\tdistinct(key: string, filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: CommandOperationOptions): Promise<T[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('distinct', this.collectionName, JSON.stringify([key, filter, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).distinct(key, <any>filter, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Distinct', this.collectionName, filter, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tdrop(options?: CommandOperationOptions): Promise<boolean> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('drop', this.collectionName, JSON.stringify([options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).drop(options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Count Documents', this.collectionName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tdropIndex(indexName: string, options?: CommandOperationOptions): Promise<Document> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('dropIndex', this.collectionName, JSON.stringify([indexName, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).dropIndex(indexName, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(<Document>res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Drop Index', this.collectionName, indexName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tdropIndexes(options?: CommandOperationOptions): Promise<Boolean> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('dropIndexes', this.collectionName, JSON.stringify([options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).dropIndexes(options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Drop Indexes', this.collectionName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tfind(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>, skipCache = false): Promise<T[]> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!skipCache) {\n\t\t\t\tResolveIOServer.getMongoManager().find(this.collectionName, filter, options).then(res => {\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet monitor = new MonitorMongo('find', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).find<T>(<any>filter, options).toArray().then(res => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Find', this.collectionName, filter, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tfindById(id: string, options?: FindOptions<T>): Promise<T> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('findById', this.collectionName, JSON.stringify([{_id: id}, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOne<T>(<any>{_id: id}, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find By Id', this.collectionName, {_id: id}, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tfindCount(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>): Promise<Number> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('findCount', this.collectionName, JSON.stringify([filter, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).find(<any>filter, options).count().then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find Count', this.collectionName, filter, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tfindCursor(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>): FindCursor {\n\t\tlet monitor = new MonitorMongo('findCursor', this.collectionName, JSON.stringify([filter, options]));\n\t\tlet cursor = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).find(<any>filter, options);\n\t\tcursor.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\tcursor.removeAllListeners();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn cursor;\n\t}\n\n\tfindStream(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>, streamOptions?: CursorStreamOptions) {\n\t\tlet monitor = new MonitorMongo('findStream', this.collectionName, JSON.stringify([filter, options, streamOptions]));\n\t\tlet stream = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).find(<any>filter, options).stream(streamOptions);\n\t\tstream.on('end', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t})\n\t\t.on('error', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t})\n\t\t.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn stream;\n\t}\n\n\tfindOne(filter: MongoManagerFilter<T> | MongoManagerFilterOperators<T> = {}, options?: FindOptions<T>, skipCache = false): Promise<T> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tif (!skipCache) {\n\t\t\t\tResolveIOServer.getMongoManager().findOne(this.collectionName, filter, options).then(res => {\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet monitor = new MonitorMongo('findOne', this.collectionName, JSON.stringify([filter, options]));\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOne<T>(<any>filter, options).then(res => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tresolve(res);\n\t\t\t\t}, err => {\n\t\t\t\t\tmonitor.finish();\n\t\t\t\t\tconsole.log(new Date(), 'Error Find One', this.collectionName, filter, options, err);\n\t\t\t\t\treject(err)\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tfindOneAndDelete(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, options?: FindOneAndDeleteOptions, bypassLogs = false): Promise<T> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('findOneAndDelete', this.collectionName, JSON.stringify([filter, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndDelete(<any>filter, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tlet doc = res;\n\t\t\t\t\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'findOneAndDelete',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t}\n\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\n\t\t\t\t\tresolve(<T>doc);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresolve(null);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find One And Delete', this.collectionName, filter, options, err);\n\t\t\t\treject(err)\n\t\t\t});\n\t\t});\n\t}\n\n\tfindOneAndReplace(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, replacement: T, options?: FindOneAndReplaceOptions, bypassLogs = false, bypassCheckSchema = false): Promise<T> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(replacement);\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - findOneAndReplace', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on findOneAndReplace - ' + this.collectionName, [validation.validationErrors(), replacement]);\n\t\t\t\t\t\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tlet date = new Date();\n\n\t\t\tif (this.timestamps) {\n\t\t\t\treplacement.updatedAt = date;\n\t\t\t}\n\n\t\t\tif (options && options.upsert) {\n\t\t\t\tif (!replacement._id) {\n\t\t\t\t\treplacement._id = objectIdHexString();\n\t\t\t\t}\n\n\t\t\t\tif (this.useVersions) {\n\t\t\t\t\treplacement.__v = 0;\n\t\t\t\t}\n\n\t\t\t\tif (this.timestamps && !replacement.createdAt) {\n\t\t\t\t\treplacement.createdAt = date;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('findOneAndReplace', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndReplace(<any>filter, replacement, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tlet doc = res;\n\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'findOneAndReplace',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t}\n\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\n\t\t\t\t\tresolve(<T>doc);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresolve(null);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find One And Replace', this.collectionName, filter, options, err);\n\t\t\t\treject(err)\n\t\t\t});\n\t\t});\n\t}\n\n\tfindOneAndUpdate(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T> = {}, update: MongoManagerUpdateFilter<T>, options?: FindOneAndUpdateOptions, bypassLogs = false, bypassCheckSchema = false): Promise<T> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(update, {modifier: true});\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - findOneAndUpdate', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on findOneAndUpdate - ' + this.collectionName, [validation.validationErrors(), update]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.timestamps) {\n\t\t\t\tlet date = new Date(); \n\t\t\t\t\n\t\t\t\tif (!update.$set) {\n\t\t\t\t\tupdate.$set = <any>{updatedAt: date};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tupdate.$set.updatedAt = date;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options && options.upsert) {\n\t\t\t\tif (!update.$setOnInsert) {\n\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\tcreatedAt: new Date()\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t_id: objectIdHexString()\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (!update.$setOnInsert._id) {\n\t\t\t\t\t\tupdate.$setOnInsert._id = objectIdHexString();\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.timestamps && !update.$setOnInsert.createdAt) {\n\t\t\t\t\t\tupdate.$setOnInsert.createdAt = new Date();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('findOneAndUpdate', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndUpdate(<any>filter, <any>update, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tlet doc = res;\n\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\t\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'findOneAndUpdate',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t}\n\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\n\t\t\t\t\tresolve(<T>doc);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresolve(null);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Find One And Update', this.collectionName, filter, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tindexes(options: IndexInformationOptions): Promise<any[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('indexes', this.collectionName, JSON.stringify([options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).indexes(options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Indexes', this.collectionName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tindexExists(indexes: string | string[], options?: IndexInformationOptions): Promise<boolean> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('indexExists', this.collectionName, JSON.stringify([indexes, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).indexExists(indexes, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Index Exists', this.collectionName, indexes, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tinsertMany(docs: T[], options?: BulkWriteOptions, bypassLogs = false, bypassCheckSchema = false, bypassMonitor = false): Promise<T[]> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!docs.length) {\n\t\t\t\tresolve([]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tlet validationResults = [];\n\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tdocs.forEach(doc => {\n\t\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\t\tconst isValid = validation.validate(doc);\n\n\t\t\t\t\tif (!isValid) {\n\t\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - insertMany', validation.validationErrors());\n\t\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on insertMany - ' + this.collectionName, [validation.validationErrors(), doc]);\n\t\t\t\t\t\tvalidationResults.push(false);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tvalidationResults.push(true);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet validDocs = this.checkSchema ? docs.filter((a, idx) => validationResults[idx]) : docs;\n\n\t\t\tfor (let i = 0; i < validDocs.length; i++) {\n\t\t\t\tlet doc = validDocs[i];\n\n\t\t\t\tif (!doc._id) {\n\t\t\t\t\tdoc._id = objectIdHexString();\n\t\t\t\t}\n\n\t\t\t\tif (this.timestamps) {\n\t\t\t\t\tlet date = new Date();\n\n\t\t\t\t\tif (!doc.createdAt) {\n\t\t\t\t\t\tdoc.createdAt = date;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!doc.updatedAt) {\n\t\t\t\t\t\tdoc.updatedAt = date;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this.useVersions && !doc.hasOwnProperty('__v')) {\n\t\t\t\t\tdoc.__v = 0;\n\t\t\t\t}\n\n\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',\n\t\t\t\t\t\tmethod: 'insertMany',\n\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\troute: ''\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (validDocs.length) {\n\t\t\t\tlet monitor = null;\n\t\t\t\t\n\t\t\t\tif (!bypassMonitor) {\n\t\t\t\t\tmonitor = new MonitorMongo('insertMany', this.collectionName, JSON.stringify([validDocs, options]));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).insertMany(<OptionalUnlessRequiredId<T>[]>validDocs, options).then(res => {\n\t\t\t\t\tif (monitor) {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t}\n\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\tresolve(validDocs);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t}\n\t\t\t\t}, err => {\n\t\t\t\t\tif (monitor) {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t}\n\t\t\t\t\tconsole.log(new Date(), 'Error Insert Many', this.collectionName, validDocs, options, err);\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tinsertOne(doc: T, options?: InsertOneOptions, bypassLogs = false, bypassCheckSchema = false): Promise<T> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!doc._id) {\n\t\t\t\tdoc._id = objectIdHexString();\n\t\t\t}\n\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(doc);\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - insertOne', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on insertOne - ' + this.collectionName, [validation.validationErrors(), doc]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.timestamps) {\n\t\t\t\tlet date = new Date();\n\t\t\t\n\t\t\t\tif (!doc.createdAt) {\n\t\t\t\t\tdoc.createdAt = date;\n\t\t\t\t}\n\n\t\t\t\tif (!doc.updatedAt) {\n\t\t\t\t\tdoc.updatedAt = date;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\tLogs.insertOne({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\ttype: 'document',\n\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',\n\t\t\t\t\tmethod: 'insertOne',\n\t\t\t\t\tid_user: '',\n\t\t\t\t\tuser: '',\n\t\t\t\t\tmessageId: 0,\n\t\t\t\t\troute: ''\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (this.useVersions && !doc.hasOwnProperty('__v')) {\n\t\t\t\tdoc.__v = 0;\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('insertOne', this.collectionName, JSON.stringify([doc, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).insertOne(<OptionalUnlessRequiredId<T>>doc, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\tresolve(doc);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Insert One', this.collectionName, doc, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\tlistIndexes(options?: ListIndexesOptions): ListIndexesCursor {\n\t\tlet monitor = new MonitorMongo('listIndexes', this.collectionName, JSON.stringify([options]));\n\t\tlet cursor = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).listIndexes(options);\n\t\tcursor.on('close', ev => {\n\t\t\tmonitor.finish();\n\t\t\treturn ev;\n\t\t});\n\n\t\treturn cursor;\n\t}\n\n\trename(newName: string, options?: RenameOptions): Promise<Collection<Document>> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet monitor = new MonitorMongo('rename', this.collectionName, JSON.stringify([newName, options]));\n\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).rename(newName, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tresolve(res);\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Rename', this.collectionName, newName, options, err);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n\n\treplaceOne(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, replacement: T, options?: ReplaceOptions, bypassLogs = false, bypassCheckSchema = false, doc: T = null) : Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(replacement);\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - replaceOne', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on replaceOne - ' + this.collectionName, [validation.validationErrors(), replacement]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tlet date = new Date();\n\t\t\t\n\t\t\tif (this.timestamps) {\n\t\t\t\treplacement.updatedAt = date;\n\t\t\t}\n\n\t\t\tif (this.useVersions) {\n\t\t\t\tif (!doc) {\n\t\t\t\t\tdoc = await this.findOne(<any>filter, null, true);\n\t\t\t\t}\n\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.timestamps && !replacement.createdAt && doc.createdAt) {\n\t\t\t\t\t\treplacement.createdAt = doc.createdAt;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (doc.__v === replacement.__v) {\n\t\t\t\t\t\treplacement.__v += 1;\n\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\n\t\t\t\t\t\tif (doc.__v >= 4) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 4}}]});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tlet monitor = new MonitorMongo('replaceOne', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).replaceOne(<any>filter, replacement, options).then(res => {\n\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, err => {\n\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Error Replace One', this.collectionName, filter, replacement, options, err);\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tconsole.log('invalid version - ' + this.collectionName, doc.__v, replacement.__v);\n\n\t\t\t\t\t\tlet prevDoc = await ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({\n\t\t\t\t\t\t\t_id: <any>{\n\t\t\t\t\t\t\t\t_id: doc._id,\n\t\t\t\t\t\t\t\t__v: replacement.__v\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, null, true);\n\n\t\t\t\t\t\tif (prevDoc) {\n\t\t\t\t\t\t\tlet docId = doc._id;\n\t\t\t\t\t\t\tlet docVersion = doc.__v;\n\t\t\t\t\t\t\tlet updatedDoc: T = getMongoMergeUpdatedDoc(replacement, doc, prevDoc);\n\t\t\t\t\t\t\tupdatedDoc._id = docId;\n\t\t\t\t\t\t\tupdatedDoc.__v = docVersion + 1;\n\n\t\t\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\t\tid_document: docId,\n\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['invalidVersion - merge', doc, filter, updatedDoc, options])) < 200000 ? JSON.stringify(['invalidVersion - merge', doc, filter, updatedDoc, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet monitor = new MonitorMongo('replaceOne', this.collectionName, JSON.stringify([filter, updatedDoc, options]));\n\t\t\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).replaceOne(<any>filter, updatedDoc, options).then(res => {\n\t\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, err => {\n\t\t\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Error Replace One', this.collectionName, filter, updatedDoc, options, err);\n\t\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject('Invalid Version And Could Not Find History - DB: ' + doc.__v + ', Trying to update with :' + replacement.__v);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (options && options.upsert) {\n\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\treplacement.createdAt = date;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!replacement._id) {\n\t\t\t\t\t\treplacement._id = objectIdHexString();\n\t\t\t\t\t}\n\n\t\t\t\t\treplacement.__v = 0;\n\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: replacement._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['upsert', filter, replacement, options])) < 200000 ? JSON.stringify(['upsert', filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tlet monitor = new MonitorMongo('replaceOne', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).replaceOne(<any>filter, replacement, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Replace One', this.collectionName, filter, replacement, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject('No Document');\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (options && options.upsert) {\n\t\t\t\t\tif (this.timestamps && !replacement.createdAt) {\n\t\t\t\t\t\treplacement.createdAt = date;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!replacement._id) {\n\t\t\t\t\t\treplacement._id = objectIdHexString();\n\t\t\t\t\t}\n\n\t\t\t\t\treplacement.__v = 0;\n\t\t\t\t}\n\n\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\tif (!options) {\n\t\t\t\t\t\toptions = <FindOneAndReplaceOptions>{returnDocument: 'before'};\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t(<FindOneAndReplaceOptions>options).returnDocument = 'before';\n\t\t\t\t\t}\n\n\t\t\t\t\tlet monitor = new MonitorMongo('findOneAndReplace', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).findOneAndReplace(<any>filter, replacement, <FindOneAndReplaceOptions>options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tlet doc = res;\n\n\t\t\t\t\t\tif (doc) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: <string>doc._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: replacement._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['upsert', filter, replacement, options])) < 200000 ? JSON.stringify(['upsert', filter, replacement, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'replaceOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\tresolve(1);\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Find One And Replace', this.collectionName, filter, replacement, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet monitor = new MonitorMongo('replaceOne', this.collectionName, JSON.stringify([filter, replacement, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).replaceOne(<any>filter, replacement, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Replace One', this.collectionName, filter, replacement, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tupdateMany(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, update: MongoManagerUpdateFilter<T>, options?: UpdateOptions, bypassLogs = false, bypassCheckSchema = false, bypassVersions = false) : Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif ((!update.$inc || JSON.stringify(update.$inc) === '{}') && (!update.$set || JSON.stringify(update.$set) === '{}') && (!update.$setOnInsert || JSON.stringify(update.$setOnInsert) === '{}') && (!update.$unset || JSON.stringify(update.$unset) === '{}')) {\n\t\t\t\tresolve(1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tif (this.timestamps) {\n\t\t\t\tlet date = new Date();\n\n\t\t\t\tif (!update.$set) {\n\t\t\t\t\tupdate.$set = <any>{updatedAt: date};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tupdate.$set.updatedAt = date;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\n\t\t\t\tconst isValid = validation.validate(update, {modifier: true});\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - updateMany', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on updateMany - ' + this.collectionName, [validation.validationErrors(), update]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((this.useVersions && !bypassVersions) || (this.createLogs && !bypassLogs)) {\n\t\t\t\tlet docs = await this.find(filter);\n\t\n\t\t\t\tfor (let i = 0; i < docs.length; i++) {\n\t\t\t\t\tlet doc = docs[i];\n\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'updateMany',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this.useVersions) {\n\t\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\t\t\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (doc.__v >= 4) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 4}}]});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (!objectContainsPropertyDeep(update, '__v')) {\n\t\t\t\t\t\t\tif (!update.$inc) {\n\t\t\t\t\t\t\t\tupdate.$inc = {__v: 1};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (!update.$inc.__v) {\n\t\t\t\t\t\t\t\tupdate.$inc.__v = 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet monitor = new MonitorMongo('updateMany', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateMany(<any>filter, update, options).then(res => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t}\n\t\t\t}, err => {\n\t\t\t\tmonitor.finish();\n\t\t\t\tconsole.log(new Date(), 'Error Update Many', this.collectionName, filter, update, options, err);\n\t\t\t\treject(err)\n\t\t\t});\n\t\t});\n\t}\n\n\tupdateOne(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, update: MongoManagerUpdateFilter<T>, options?: UpdateOptions, bypassLogs = false, bypassCheckSchema = false) : Promise<number> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (this.checkSchema && !bypassCheckSchema) {\n\t\t\t\tconst validation = this.simplschema.newContext();\t\t\t\n\t\t\t\tconst isValid = validation.validate(update, {modifier: true});\n\n\t\t\t\tif (!isValid) {\n\t\t\t\t\tconsole.log(new Date(), this.collectionName, 'Schema Errors - updateOne', validation.validationErrors());\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethodInternal.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertErrorLog', 'Schema Failed on updateOne - ' + this.collectionName, [validation.validationErrors(), update]);\n\t\t\t\t\treject(validation.validationErrors());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((!update.$inc || JSON.stringify(update.$inc) === '{}') && (!update.$set || JSON.stringify(update.$set) === '{}') && (!update.$setOnInsert || JSON.stringify(update.$setOnInsert) === '{}') && (!update.$unset || JSON.stringify(update.$unset) === '{}')) {\n\t\t\t\tresolve(1);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet date = new Date();\n\n\t\t\tif (this.timestamps) {\n\t\t\t\tif (!update.$set) {\n\t\t\t\t\tupdate.$set = <any>{updatedAt: date};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tupdate.$set.updatedAt = date;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (this.useVersions) {\n\t\t\t\tlet doc = await this.findOne(filter, null, true);\n\n\t\t\t\tif (doc) {\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: doc._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'updateOne',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tlet versionDoc = deepCopy(doc);\n\t\t\t\t\tversionDoc._id = {_id: doc._id, __v: doc.__v};\n\t\n\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne(<any>{_id: { _id: doc._id, __v: doc.__v}}, versionDoc, {upsert: true});\n\t\t\t\t\t\n\t\t\t\t\tif (doc.__v >= 4) {\n\t\t\t\t\t\tResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany(<any>{$and: [{'_id._id': doc._id}, {'_id.__v': {$lt: doc.__v - 4}}]});\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (!objectContainsPropertyDeep(update, '__v')) {\n\t\t\t\t\t\tif (!update.$inc) {\n\t\t\t\t\t\t\tupdate.$inc = {__v: 1};\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (!update.$inc.__v) {\n\t\t\t\t\t\t\tupdate.$inc.__v = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tlet monitor = new MonitorMongo('updateOne', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateOne(<any>filter, update, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Update One', this.collectionName, filter, update, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse if (options && options.upsert) {\n\t\t\t\t\tif (!update.$setOnInsert) {\n\t\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\tcreatedAt: new Date()\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t__v: 0\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (!update.$setOnInsert._id) {\n\t\t\t\t\t\t\tupdate.$setOnInsert._id = objectIdHexString();\n\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\tif (this.timestamps && !update.$setOnInsert.createdAt) {\n\t\t\t\t\t\t\tupdate.$setOnInsert.createdAt = new Date();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\tid_document: update.$setOnInsert._id,\n\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['upsert', filter, update, options])) < 200000 ? JSON.stringify(['upsert', filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\tmethod: 'updateOne',\n\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tlet monitor = new MonitorMongo('updateOne', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateOne(<any>filter, update, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Update One', this.collectionName, filter, update, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treject('No Document');\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (options && options.upsert) {\n\t\t\t\t\tif (!update.$setOnInsert) {\n\t\t\t\t\t\tif (this.timestamps) {\n\t\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\tcreatedAt: new Date()\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tupdate.$setOnInsert = <any>{\n\t\t\t\t\t\t\t\t_id: objectIdHexString()\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (!update.$setOnInsert._id) {\n\t\t\t\t\t\t\tupdate.$setOnInsert._id = objectIdHexString();\n\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\tif (this.timestamps && !update.$setOnInsert.createdAt) {\n\t\t\t\t\t\t\tupdate.$setOnInsert.createdAt = new Date();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this.createLogs && !bypassLogs) {\n\t\t\t\t\tif (!options) {\n\t\t\t\t\t\toptions = <FindOneAndUpdateOptions>{returnDocument: 'before'};\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t(<FindOneAndUpdateOptions>options).returnDocument = 'before';\n\t\t\t\t\t}\n\n\t\t\t\t\tlet monitor = new MonitorMongo('findOneAndUpdate', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).findOneAndUpdate(<any>filter, update, <FindOneAndUpdateOptions>options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tlet doc = res.value;\n\n\t\t\t\t\t\tif (doc) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: <any>doc._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'updateOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tresolve(res.ok);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (update.$setOnInsert) {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'document',\n\t\t\t\t\t\t\t\tcollection: this.collectionName,\n\t\t\t\t\t\t\t\tid_document: update.$setOnInsert._id,\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(['upsert', filter, update, options])) < 200000 ? JSON.stringify(['upsert', filter, update, options], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'updateOne',\n\t\t\t\t\t\t\t\tid_user: '',\n\t\t\t\t\t\t\t\tuser: '',\n\t\t\t\t\t\t\t\tmessageId: 0,\n\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\n\t\t\t\t\t\t\tresolve(res.ok);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tresolve(0);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Find One And Update', this.collectionName, filter, update, options, err);\n\t\t\t\t\t\treject(err)\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet monitor = new MonitorMongo('updateOne', this.collectionName, JSON.stringify([filter, update, options]));\n\t\t\t\t\tResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateOne(<any>filter, update, options).then(res => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tif (res.acknowledged) {\n\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);\n\t\t\t\t\t\t\tresolve(res.modifiedCount);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject(res.acknowledged);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, err => {\n\t\t\t\t\t\tmonitor.finish();\n\t\t\t\t\t\tconsole.log(new Date(), 'Error Update One', this.collectionName, filter, update, options, err);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t\n\twatchCollection(pipeline = [], options?: ChangeStreamOptions): ChangeStream<T> {\n\t\tlet stream = ResolveIOServer.getMainDB().collection<T>(this.collectionName, this.collectionOptions).watch(pipeline, options);\n\t\treturn <ChangeStream<T>>stream;\n\t}\n}\n\nexport class MongoManagerUserCollection<T extends CollectionDocument> extends MongoManagerCollection<T> {\n\tauthenticate(user: UserModel, password: string): Promise<{data: UserModel, error: string}> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tconst attemptsInterval = Math.pow(100, Math.log(user.attempts + 1));\n\t\t\tconst calculatedInterval = attemptsInterval < 300000 ? attemptsInterval : 300000;\n\t\t\n\t\t\tif (user.last) {\n\t\t\t\tif (Date.now() - user.last.getTime() < calculatedInterval) {\n\t\t\t\t\tuser.last = new Date();\n\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {last: user.last}});\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: 'Attempt Too Soon'\n\t\t\t\t\t});\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tuser.last = new Date();\n\t\t\t}\n\t\t\n\t\t\tif (user.attempts >= 5) {\n\t\t\t\tresolve({\n\t\t\t\t\tdata: null,\n\t\t\t\t\terror: 'Too Many Attempts'\n\t\t\t\t});\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tif (!user.salt) {\n\t\t\t\tresolve({\n\t\t\t\t\tdata: null,\n\t\t\t\t\terror: 'No Salt Value Stored'\n\t\t\t\t});\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tpbkdf2(password, user.salt, {\n\t\t\t\titerations: 25000,\n\t\t\t\tkeylen: 512,\n\t\t\t\tdigestAlgorithm: 'sha256'\n\t\t\t}, async (err, hashBuffer) => {\n\t\t\t\tif (err) {\n\t\t\t\t\treturn reject(err);\n\t\t\t\t}\n\t\t\t\n\t\t\t\tif (scmp(hashBuffer, Buffer.from(user.hash, 'hex'))) {\n\t\t\t\t\tuser.last = new Date();\n\t\t\t\t\tuser.attempts = 0;\n\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {last: user.last, attempts: user.attempts}});\n\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tdata: user,\n\t\t\t\t\t\terror: ''\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tuser.last = new Date();\n\t\t\t\t\tuser.attempts = user.attempts + 1;\n\t\t\t\t\tawait Users.updateOne({_id: user._id}, {$set: {last: user.last, attempts: user.attempts}});\n\n\t\t\t\t\tif (user.attempts >= 5) {\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\terror: 'Too Many Attempts'\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\terror: 'Invalid Username And Password'\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} \n\t\t\t});\n\t\t});\n\t}\n\n\tserializeUser() {\n\t\treturn (user, cb) => {\n\t\t\tcb(null, user.username);\n\t\t};\n\t}\n\n\tdeserializeUser() {\n\t\treturn (username, cb) => {\n\t\t\tUsers.findOne({username: username}).then(res => {\n\t\t\t\tcb(null, res);\n\t\t\t}, err => {\n\t\t\t\tcb(err, null);\n\t\t\t});\n\t\t};\n\t}\n\n\tsetPassword(user: UserModel, password: string) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!user) {\n\t\t\t\treject('No User');\n\t\t\t}\n\t\t\telse if (!password) {\n\t\t\t\treject('No Password');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet saltBuffer = await randomBytes(32);\n\t\t\t\tlet salt = saltBuffer.toString('hex');\n\t\t\t\tlet hashRaw = await pbkdf2Promisified(password, salt, {\n\t\t\t\t\titerations: 25000,\n\t\t\t\t\tkeylen: 512,\n\t\t\t\t\tdigestAlgorithm: 'sha256'\n\t\t\t\t});\n\t\t\t\tlet hash = Buffer.from(hashRaw, 'binary').toString('hex');\n\t\t\t\tUsers.updateOne({_id: user._id}, {$set: {hash: hash, salt: salt, services: {}, attempts: 0}}).then(res => resolve(res), rej => reject(rej));\n\t\t\t}\n\t\t});\n\t};\n\n\tchangePassword(user, oldPassword, newPassword) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!user) {\n\t\t\t\treject('Missing User');\n\t\t\t}\n\t\t\telse if (!oldPassword || !newPassword) {\n\t\t\t\treject('Missing Password');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet authUser = await this.authenticate(user, oldPassword);\n\n\t\t\t\tif (!authUser['data']) {\n\t\t\t\t\treject(authUser['error']);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis.setPassword(user, newPassword).then(res => resolve(res), rej => reject(rej));\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t\n\tregister(user, password) {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (!user.username) {\n\t\t\t\treject('Missing Username');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet dbUser = await Users.findOne({username: user.username});\n\t\t\t\t\n\t\t\t\tif (dbUser) {\n\t\t\t\t\treject('Username Exists');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdbUser = await Users.findOne({email: user.email});\n\n\t\t\t\t\tif (dbUser) {\n\t\t\t\t\t\treject('Email Exists');\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tuser.setPassword(password);\n\t\t\t\t\t\tresolve(user);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tresetAttempts(user: UserModel) {\n\t\treturn Users.updateOne({_id: user._id}, {$set: {attempts: 0}});\n\t}\n}\n\nexport function objectIdHexString() {\n\tlet objectId = new ObjectId();\n\treturn objectId.toHexString();\n}\n\nfunction pbkdf2(password, salt, options, callback) {\n\tcrypto.pbkdf2(password, salt, options.iterations, options.keylen, options.digestAlgorithm, callback);\n};\n\nfunction pbkdf2Promisified(password, salt, options): Promise<any> {\n\treturn new Promise((resolve, reject) => pbkdf2(password, salt, options, (err, hashRaw) => (err ? reject(err) : resolve(hashRaw))));\n}\n\nfunction randomBytes(saltlen): Promise<Buffer> {\n\treturn new Promise((resolve, reject) => crypto.randomBytes(saltlen, (err, saltBuffer) => (err ? reject(err) : resolve(saltBuffer))));\n}\n\nfunction objectContainsPropertyDeep(obj: Object, prop: string) {\n\tlet keys = Object.keys(obj);\n\n\tif (keys.some(a => a === prop)) {\n\t\treturn true;\n\t}\n\t\n\tfor (let i = 0; i < keys.length; i++) {\n\t\tlet key = keys[i];\n\t\tif (obj[key] && typeof obj[key] === 'object' && objectContainsPropertyDeep(obj[key], prop)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}"]}