A simple work in progress Abstract syntax tree (AST) builder that can be converted to JSON, Mongo Query and Mongo Query Expression.
Here is some simple examples.
import { CompoundCondition, FieldCondition } from "@aiflow/mast"
const ast = new CompoundCondition("and", [
new FieldCondition("eq", "name", "Vemund Eldegard)
])
return ast.toQuery()
Will return:
{
"$and": [
{
"name": {
"$eq": "Vemund Eldegard
}
}
]
}
import { CompoundCondition, FieldCondition } from "@aiflow/mast"
const ast = new CompoundCondition("and", [
new FieldCondition("eq", "name", "Vemund Eldegard)
])
return ast.toQueryExpression()
Will return:
{
"$expr": {
$and: [
{
"$eq": ["$name", "Vemund Eldegard"]
}
]
}
}