This needs only minimal interaction with database if can feed cache with change stream or pre/post hooks or on model creation/delete calls. Can be easily hooked up with cache event's to push data to presentation layers.(i.e. websockets, other services)
constcarChunkSession: ChunkSession<ICar>=CarCache.getChunkSession(1000,{sort: (a,b)=>a.name.localeCompare(b.name)});constiter: IterableIterator<DocumentCacheSessionChunk<ICar>>=carChunkSession.getIterator();letcurrent: IteratorResult<DocumentCacheSessionChunk<ICar>>=iter.next();while(!current.done){constvalue: DocumentCacheSessionChunk<ICar>=current.value;values.total// total number of documents in cachevalues.current// current number of iterated documentsvalues.chunk// array of 1000 or less documents in this chunk}// you can check if there is more chunks based on current iterated documents and total documents in cache// or wait for next chunk to be .done === true