https://github.com/erfanium/mongo-aggregate-shorthand
A short-hand tool for creating mongodb aggregates!
https://github.com/erfanium/mongo-aggregate-shorthand
Last synced: about 1 year ago
JSON representation
A short-hand tool for creating mongodb aggregates!
- Host: GitHub
- URL: https://github.com/erfanium/mongo-aggregate-shorthand
- Owner: erfanium
- License: mit
- Created: 2020-10-07T23:35:06.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-08T14:16:39.000Z (over 5 years ago)
- Last Synced: 2025-02-05T12:46:11.840Z (over 1 year ago)
- Language: TypeScript
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongo-aggregate-shorthand
A short-hand system for creating Mongodb aggregates! Great for analytics stuff with Mongodb
## Example
```sh
MATCH examID=1 && sandbox=false && ratio > 10
SORT percent -1
LOOKUP users userID:_id as user
SET user=user[0]
PROJECT percent user ratio
```
equals
```js
[
{
$match: {
examID: 1,
sandbox: false,
ratio: { $gt: 10 }
},
},
{
$sort: {
percent: -1,
},
},
{
$lookup: {
from: 'users',
localField: 'userID',
foreignField: '_id',
as: 'user',
},
},
{
$set: {
user: { $arrayElemAt: ['$user', 0] },
},
},
{
$project: {
percent: 1,
user: 1,
ratio: 1,
},
}
]
```
## Usage:
clone repo then:
- Install dependencies:
```sh
npm i
```
- To parse from file:
```sh
npm run file example.txt
```
- REPL mode:
```sh
npm run repl
```
## Stage
Implementation, Give us your opinion!