diff --git a/packages/nodes-base/nodes/MongoDb/MongoDb.node.ts b/packages/nodes-base/nodes/MongoDb/MongoDb.node.ts index 1a200d9bd9..8d5de2ea41 100644 --- a/packages/nodes-base/nodes/MongoDb/MongoDb.node.ts +++ b/packages/nodes-base/nodes/MongoDb/MongoDb.node.ts @@ -196,6 +196,8 @@ export class MongoDb implements INodeType { const options = this.getNodeParameter('options', i); const limit = options.limit 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); if (skip > 0) { @@ -208,6 +210,10 @@ export class MongoDb implements INodeType { query = query.sort(sort); } + if (projection && projection instanceof Document) { + query = query.project(projection); + } + const queryResult = await query.toArray(); for (const entry of queryResult) { diff --git a/packages/nodes-base/nodes/MongoDb/MongoDbProperties.ts b/packages/nodes-base/nodes/MongoDb/MongoDbProperties.ts index a831bd57fa..95b7fb93a5 100644 --- a/packages/nodes-base/nodes/MongoDb/MongoDbProperties.ts +++ b/packages/nodes-base/nodes/MongoDb/MongoDbProperties.ts @@ -151,6 +151,18 @@ export const nodeProperties: INodeProperties[] = [ placeholder: '{ "field": -1 }', 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', type: 'string', 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',