const $project = require("mongo-to-sql").$project;
or
const $project = require("mongo-to-sql/stages/project");
$project(stage, tableName, options);
headless
- Boolean
- Defaults to
false
- When specified as
true
, it will remove the FROM keyword and the assosiated table name from the generated query.
tableCounter
- Integer
- When not specified or specified as 0, it will cause the table name to be escaped.
- If it is greater than 0, the table name will not be escaped as it is assumed to be a subquery.
- If you exclude fields, you cannot also specify the inclusion of fields.
- Fields with expressions will automatically have their expressions converted to their appropriate forms.
- The
_id
field is not included by default.
- $concat
- $toLower
- $toUpper
$project({
"field1": 1,
"field2": 1
}, "tableName");
$project({
"field1": 0,
"field2": 0
}, "tableName");
$project({
"concatenatedFieldName": {
"$concat": [ "$field1", " - ", "$field2" ]
}
}, "tableName");
$project({
"lowercaseFieldName": {
"$toLower": "$field1"
},
"lowercaseFieldName2": {
"$toLower": "HELLO WORLD"
}
}, "tableName");
$project({
"uppercaseFieldName": {
"$toUpper": "$field1"
},
"uppercaseFieldName2": {
"$toUpper": "hello world"
}
}, "tableName");