Transform typescript (or javascript) snippets to mongodb aggregation pipeline objects https://docs.mongodb.com/manual/aggregation/
npm i -D typescript-transform-mongo # Soon!
Usage with ttypescript
Add it to plugins in your tsconfig.json
{
"compilerOptions": {
"plugins": [{ "transform": "typescript-transform-mongo" }]
}
}
declare function aggregateOp(fn: any): object;
const pipeline = [
{
$addFields: {
x: aggregateOp(function (this: { y: number }) {
return this.y + 3;
}),
},
},
];
Gets compiled to:
const pipeline = [
{
$addFields: {
x: { $add: ["$y", { $literal: 3 }] },
},
},
];
dir: https://github.com/LeDDGroup/typescript-transform-mongo/tree/master/examples
make sure to build the project first:
npm run build
cd examples
npx ttsc
Checkout the test files under src/ for failing and pending tests. PRs and issues are welcome.
We are using jest
for tests, so:
npm test # or npx jest
npm test -- --watch # or npx jest --watch