Skip to content

Instantly share code, notes, and snippets.

@baranovxyz
Created May 11, 2020 21:00
Show Gist options
  • Save baranovxyz/8fc9691278a9406c05122fb0f48eec6a to your computer and use it in GitHub Desktop.
Save baranovxyz/8fc9691278a9406c05122fb0f48eec6a to your computer and use it in GitHub Desktop.
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