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:
Mickaël Andrieu 2024-08-07 11:39:44 +02:00 committed by GitHub
parent c5acbb7ec0
commit 0a84e0d8b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -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) {

View file

@ -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',