mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
Feature/paired item support (#3869)
* Add paired item helper and implement it in some nodes
This commit is contained in:
@@ -36,7 +36,8 @@ export class MongoDb implements INodeType {
|
||||
|
||||
const mdb = client.db(database as string);
|
||||
|
||||
let returnItems = [];
|
||||
const returnItems: INodeExecutionData[] = [];
|
||||
let responseData: IDataObject | IDataObject[] = [];
|
||||
|
||||
const items = this.getInputData();
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
@@ -57,12 +58,11 @@ export class MongoDb implements INodeType {
|
||||
.collection(this.getNodeParameter('collection', 0) as string)
|
||||
.aggregate(queryParameter);
|
||||
|
||||
const queryResult = await query.toArray();
|
||||
responseData = await query.toArray();
|
||||
|
||||
returnItems = this.helpers.returnJsonArray(queryResult as IDataObject[]);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnItems = this.helpers.returnJsonArray({ error: (error as JsonObject).message });
|
||||
responseData = [ { error: (error as JsonObject).message } ];
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
@@ -77,10 +77,10 @@ export class MongoDb implements INodeType {
|
||||
.collection(this.getNodeParameter('collection', 0) as string)
|
||||
.deleteMany(JSON.parse(this.getNodeParameter('query', 0) as string));
|
||||
|
||||
returnItems = this.helpers.returnJsonArray([{ deletedCount }]);
|
||||
responseData = [{ deletedCount }];
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnItems = this.helpers.returnJsonArray({ error: (error as JsonObject).message });
|
||||
responseData = [{ error: (error as JsonObject).message }];
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
@@ -116,10 +116,10 @@ export class MongoDb implements INodeType {
|
||||
}
|
||||
const queryResult = await query.toArray();
|
||||
|
||||
returnItems = this.helpers.returnJsonArray(queryResult as IDataObject[]);
|
||||
responseData = queryResult;
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnItems = this.helpers.returnJsonArray({ error: (error as JsonObject).message });
|
||||
responseData = [{ error: (error as JsonObject).message }];
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
@@ -150,16 +150,14 @@ export class MongoDb implements INodeType {
|
||||
|
||||
// Add the id to the data
|
||||
for (const i of Object.keys(insertedIds)) {
|
||||
returnItems.push({
|
||||
json: {
|
||||
...insertItems[parseInt(i, 10)],
|
||||
id: insertedIds[parseInt(i, 10)] as string,
|
||||
},
|
||||
responseData.push({
|
||||
...insertItems[parseInt(i, 10)],
|
||||
id: insertedIds[parseInt(i, 10)] as string,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnItems = this.helpers.returnJsonArray({ error: (error as JsonObject).message });
|
||||
responseData = [{ error: (error as JsonObject).message }];
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
@@ -219,21 +217,25 @@ export class MongoDb implements INodeType {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
returnItems = this.helpers.returnJsonArray(updateItems as IDataObject[]);
|
||||
|
||||
responseData = updateItems;
|
||||
} else {
|
||||
if (this.continueOnFail()) {
|
||||
returnItems = this.helpers.returnJsonArray({
|
||||
json: { error: `The operation "${operation}" is not supported!` },
|
||||
});
|
||||
responseData = [{ error: `The operation "${operation}" is not supported!` }];
|
||||
} else {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`The operation "${operation}" is not supported!`,
|
||||
);
|
||||
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not supported!`, {itemIndex: 0});
|
||||
}
|
||||
}
|
||||
|
||||
client.close();
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData),
|
||||
{ itemData: { item: 0 } },
|
||||
);
|
||||
|
||||
returnItems.push(...executionData);
|
||||
|
||||
return this.prepareOutputData(returnItems);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user