Skip to content

Instantly share code, notes, and snippets.

@jgdev
Last active August 20, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgdev/c01cb8a56aa3fd2ffc099acf9f685e6f to your computer and use it in GitHub Desktop.
Save jgdev/c01cb8a56aa3fd2ffc099acf9f685e6f to your computer and use it in GitHub Desktop.
/**
* Example data in the collection:
*
* [
* { _id: ObjectId(), key: "foo", value: "bar" },
* { _id: ObjectId(), key: "fbKey", value: "123" },
* { _id: ObjectId(), key: "logoUrl", value: "https://my-site.s3.aws.us-east-1/logo.png" },
* ]
*/
async getPortfolioSettings = () => {
const portfolioSettings = await db.getCollection("portfolio_settings").find({});
return portfolioSettings.reduce((result, { key, value }) => ({
...result, [key]: value,
}), {});
}
getPortfolioSettings().then(console.log)
/**
* Expected output:
*
* {
* foo: "bar",
* fbKey: "123",
* logoUrl: "https://my-site.s3.aws.us-east-1/logo.png"
* }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment