mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
feat(MongoDB Node): Add projection to query options on Find (#9972)
Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
This commit is contained in:
parent
c5acbb7ec0
commit
0a84e0d8b0
|
@ -196,6 +196,8 @@ export class MongoDb implements INodeType {
|
||||||
const options = this.getNodeParameter('options', i);
|
const options = this.getNodeParameter('options', i);
|
||||||
const limit = options.limit as number;
|
const limit = options.limit as number;
|
||||||
const skip = options.skip as number;
|
const skip = options.skip as number;
|
||||||
|
const projection =
|
||||||
|
options.projection && (JSON.parse(options.projection as string) as Document);
|
||||||
const sort = options.sort && (JSON.parse(options.sort as string) as Sort);
|
const sort = options.sort && (JSON.parse(options.sort as string) as Sort);
|
||||||
|
|
||||||
if (skip > 0) {
|
if (skip > 0) {
|
||||||
|
@ -208,6 +210,10 @@ export class MongoDb implements INodeType {
|
||||||
query = query.sort(sort);
|
query = query.sort(sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (projection && projection instanceof Document) {
|
||||||
|
query = query.project(projection);
|
||||||
|
}
|
||||||
|
|
||||||
const queryResult = await query.toArray();
|
const queryResult = await query.toArray();
|
||||||
|
|
||||||
for (const entry of queryResult) {
|
for (const entry of queryResult) {
|
||||||
|
|
|
@ -151,6 +151,18 @@ export const nodeProperties: INodeProperties[] = [
|
||||||
placeholder: '{ "field": -1 }',
|
placeholder: '{ "field": -1 }',
|
||||||
description: 'A JSON that defines the sort order of the result set',
|
description: 'A JSON that defines the sort order of the result set',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Projection (JSON Format)',
|
||||||
|
name: 'projection',
|
||||||
|
type: 'json',
|
||||||
|
typeOptions: {
|
||||||
|
rows: 4,
|
||||||
|
},
|
||||||
|
default: '{}',
|
||||||
|
placeholder: '{ "_id": 0, "field": 1 }',
|
||||||
|
description:
|
||||||
|
'A JSON that defines a selection of fields to retrieve or exclude from the result set',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -248,7 +260,7 @@ export const nodeProperties: INodeProperties[] = [
|
||||||
name: 'dateFields',
|
name: 'dateFields',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Comma separeted list of fields that will be parsed as Mongo Date type',
|
description: 'Comma-separated list of fields that will be parsed as Mongo Date type',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Use Dot Notation',
|
displayName: 'Use Dot Notation',
|
||||||
|
|
Loading…
Reference in a new issue