Improve projection in example to flatten picking a single field
This commit is contained in:
parent
ad430a3173
commit
d12a5e7cf2
|
@ -74,12 +74,16 @@
|
||||||
if (projection) {
|
if (projection) {
|
||||||
// It is possible to make a util function "pickFlat"
|
// It is possible to make a util function "pickFlat"
|
||||||
// and use that when building the query to make it more readable.
|
// and use that when building the query to make it more readable.
|
||||||
const fields = projection.fields.map(field => {
|
if (projection.fields.length > 1) {
|
||||||
const name = _.last(field.split('.'))
|
const fields = projection.fields.map(field => {
|
||||||
return ` '${name}': _.get(item, '${field}')`
|
const name = _.last(field.split('.'))
|
||||||
})
|
return ` '${name}': _.get(item, '${field}')`
|
||||||
|
})
|
||||||
query = `_.map(${query}, item => ({\n${fields.join(',\n')}})\n)`
|
query = `_.map(${query}, item => ({\n${fields.join(',\n')}})\n)`
|
||||||
|
} else {
|
||||||
|
const field = projection.fields[0]
|
||||||
|
query = `_.map(${query}, item => _.get(item, '${field}'))`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
Loading…
Reference in New Issue