Created
May 11, 2020 21:00
-
-
Save baranovxyz/8fc9691278a9406c05122fb0f48eec6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function findOneMongoDB(query) { | |
/* implemented somewhere */ | |
} | |
async function get(query) { | |
let doc = await findOneMongoDB(query); | |
// return doc at once if it is not splitted | |
if (!doc._splitted) return doc; | |
const { _id, type } = doc; | |
const values = []; | |
while (doc._next) { | |
// our doc and its chunks is a linked list | |
// empty[] -> values[] -> values[] | |
// id of the next chunk is in `_next` property | |
doc = await get({ _id: doc._next }); | |
// here we will use for..of statement | |
// read about benefits https://medium.com/@baranovxyz/499269312eaf | |
for (const value of doc.values) { | |
values.push(value); | |
} | |
} | |
return { _id, type, values }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment