mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
enhance .editorconfig and apply formatting cleanup to last commit
This commit is contained in:
parent
c6aa73cc2f
commit
00fc6e5980
|
@ -6,3 +6,10 @@ indent_style = tab
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[package.json]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.ts]
|
||||||
|
quote_type = single
|
|
@ -1,41 +1,41 @@
|
||||||
import { IExecuteFunctions } from "n8n-core";
|
import { IExecuteFunctions } from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription
|
||||||
} from "n8n-workflow";
|
} from 'n8n-workflow';
|
||||||
import { nodeDescription } from "./mongo.node.options";
|
import { nodeDescription } from './mongo.node.options';
|
||||||
import { MongoClient } from "mongodb";
|
import { MongoClient } from 'mongodb';
|
||||||
import { getItemCopy, buildParameterizedConnString } from "./mongo.node.utils";
|
import { getItemCopy, buildParameterizedConnString } from './mongo.node.utils';
|
||||||
|
|
||||||
export class MongoDb implements INodeType {
|
export class MongoDb implements INodeType {
|
||||||
description: INodeTypeDescription = nodeDescription;
|
description: INodeTypeDescription = nodeDescription;
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const credentials = this.getCredentials("mongoDb");
|
const credentials = this.getCredentials('mongoDb');
|
||||||
|
|
||||||
// user can optionally override connection string
|
// user can optionally override connection string
|
||||||
const useOverriddenConnString = this.getNodeParameter(
|
const useOverriddenConnString = this.getNodeParameter(
|
||||||
"shouldOverrideConnString",
|
'shouldOverrideConnString',
|
||||||
0
|
0
|
||||||
) as boolean;
|
) as boolean;
|
||||||
|
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
throw new Error("No credentials got returned!");
|
throw new Error('No credentials got returned!');
|
||||||
}
|
}
|
||||||
|
|
||||||
let connectionUri = "";
|
let connectionUri = '';
|
||||||
if (useOverriddenConnString === true) {
|
if (useOverriddenConnString === true) {
|
||||||
const connStringInput = this.getNodeParameter(
|
const connStringInput = this.getNodeParameter(
|
||||||
"connStringOverrideVal",
|
'connStringOverrideVal',
|
||||||
0
|
0
|
||||||
) as string;
|
) as string;
|
||||||
if (connStringInput && connStringInput.length > 0) {
|
if (connStringInput && connStringInput.length > 0) {
|
||||||
connectionUri = connStringInput;
|
connectionUri = connStringInput;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Cannot override credentials: valid MongoDB connection string not provided "
|
'Cannot override credentials: valid MongoDB connection string not provided '
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,7 +44,7 @@ export class MongoDb implements INodeType {
|
||||||
|
|
||||||
const client: MongoClient = await MongoClient.connect(connectionUri, {
|
const client: MongoClient = await MongoClient.connect(connectionUri, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const mdb = client.db(credentials.database as string);
|
const mdb = client.db(credentials.database as string);
|
||||||
|
@ -52,34 +52,34 @@ export class MongoDb implements INodeType {
|
||||||
let returnItems = [];
|
let returnItems = [];
|
||||||
|
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const operation = this.getNodeParameter("operation", 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
|
||||||
if (operation === "find") {
|
if (operation === 'find') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// find
|
// find
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
const queryResult = await mdb
|
const queryResult = await mdb
|
||||||
.collection(this.getNodeParameter("collection", 0) as string)
|
.collection(this.getNodeParameter('collection', 0) as string)
|
||||||
.find(JSON.parse(this.getNodeParameter("query", 0) as string))
|
.find(JSON.parse(this.getNodeParameter('query', 0) as string))
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
returnItems = this.helpers.returnJsonArray(queryResult as IDataObject[]);
|
returnItems = this.helpers.returnJsonArray(queryResult as IDataObject[]);
|
||||||
} else if (operation === "insert") {
|
} else if (operation === 'insert') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// insert
|
// insert
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
// Prepare the data to insert and copy it to be returned
|
// Prepare the data to insert and copy it to be returned
|
||||||
const fields = (this.getNodeParameter("fields", 0) as string)
|
const fields = (this.getNodeParameter('fields', 0) as string)
|
||||||
.split(",")
|
.split(',')
|
||||||
.map((f) => f.trim())
|
.map(f => f.trim())
|
||||||
.filter((f) => !!f);
|
.filter(f => !!f);
|
||||||
|
|
||||||
const insertItems = getItemCopy(items, fields);
|
const insertItems = getItemCopy(items, fields);
|
||||||
|
|
||||||
const { insertedIds } = await mdb
|
const { insertedIds } = await mdb
|
||||||
.collection(this.getNodeParameter("collection", 0) as string)
|
.collection(this.getNodeParameter('collection', 0) as string)
|
||||||
.insertMany(insertItems);
|
.insertMany(insertItems);
|
||||||
|
|
||||||
// Add the id to the data
|
// Add the id to the data
|
||||||
|
@ -87,21 +87,21 @@ export class MongoDb implements INodeType {
|
||||||
returnItems.push({
|
returnItems.push({
|
||||||
json: {
|
json: {
|
||||||
...insertItems[parseInt(i, 10)],
|
...insertItems[parseInt(i, 10)],
|
||||||
id: insertedIds[parseInt(i, 10)] as string,
|
id: insertedIds[parseInt(i, 10)] as string
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (operation === "update") {
|
} else if (operation === 'update') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// update
|
// update
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
const fields = (this.getNodeParameter("fields", 0) as string)
|
const fields = (this.getNodeParameter('fields', 0) as string)
|
||||||
.split(",")
|
.split(',')
|
||||||
.map((f) => f.trim())
|
.map(f => f.trim())
|
||||||
.filter((f) => !!f);
|
.filter(f => !!f);
|
||||||
|
|
||||||
let updateKey = this.getNodeParameter("updateKey", 0) as string;
|
let updateKey = this.getNodeParameter('updateKey', 0) as string;
|
||||||
updateKey = updateKey.trim();
|
updateKey = updateKey.trim();
|
||||||
|
|
||||||
if (!fields.includes(updateKey)) {
|
if (!fields.includes(updateKey)) {
|
||||||
|
@ -120,7 +120,7 @@ export class MongoDb implements INodeType {
|
||||||
filter[updateKey] = item[updateKey] as string;
|
filter[updateKey] = item[updateKey] as string;
|
||||||
|
|
||||||
await mdb
|
await mdb
|
||||||
.collection(this.getNodeParameter("collection", 0) as string)
|
.collection(this.getNodeParameter('collection', 0) as string)
|
||||||
.updateOne(filter, { $set: item });
|
.updateOne(filter, { $set: item });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,156 +1,156 @@
|
||||||
import { INodeTypeDescription } from "n8n-workflow";
|
import { INodeTypeDescription } from 'n8n-workflow';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options to be displayed
|
* Options to be displayed
|
||||||
*/
|
*/
|
||||||
export const nodeDescription: INodeTypeDescription = {
|
export const nodeDescription: INodeTypeDescription = {
|
||||||
displayName: "MongoDB",
|
displayName: 'MongoDB',
|
||||||
name: "mongoDb",
|
name: 'mongoDb',
|
||||||
icon: "file:mongoDb.png",
|
icon: 'file:mongoDb.png',
|
||||||
group: ["input"],
|
group: ['input'],
|
||||||
version: 1,
|
version: 1,
|
||||||
description: "Find, insert and update documents in MongoDB.",
|
description: 'Find, insert and update documents in MongoDB.',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: "MongoDB",
|
name: 'MongoDB',
|
||||||
color: "#13AA52",
|
color: '#13AA52'
|
||||||
},
|
},
|
||||||
inputs: ["main"],
|
inputs: ['main'],
|
||||||
outputs: ["main"],
|
outputs: ['main'],
|
||||||
credentials: [
|
credentials: [
|
||||||
{
|
{
|
||||||
name: "mongoDb",
|
name: 'mongoDb',
|
||||||
required: true,
|
required: true
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
displayName: "Override conn string",
|
displayName: 'Override conn string',
|
||||||
name: "shouldOverrideConnString",
|
name: 'shouldOverrideConnString',
|
||||||
type: "boolean",
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
description:
|
description:
|
||||||
"Whether to override the generated connection string. Credentials will also be ignored in this case.",
|
'Whether to override the generated connection string. Credentials will also be ignored in this case.'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: "Conn string",
|
displayName: 'Conn string',
|
||||||
name: "connStringOverrideVal",
|
name: 'connStringOverrideVal',
|
||||||
type: "string",
|
type: 'string',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
rows: 1,
|
rows: 1
|
||||||
},
|
},
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
shouldOverrideConnString: [true],
|
shouldOverrideConnString: [true]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
default: '',
|
||||||
default: "",
|
|
||||||
placeholder: `mongodb://USERNAMEHERE:PASSWORDHERE@localhost:27017/?authSource=admin&readPreference=primary&appname=n8n&ssl=false`,
|
placeholder: `mongodb://USERNAMEHERE:PASSWORDHERE@localhost:27017/?authSource=admin&readPreference=primary&appname=n8n&ssl=false`,
|
||||||
required: false,
|
required: false,
|
||||||
description: `If "Override conn string" is checked, the value here will be used as a MongoDB connection string, and the MongoDB credentials will be ignored`,
|
description: `If "Override conn string" is checked, the value here will be used as a MongoDB connection string, and the MongoDB credentials will be ignored`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: "Operation",
|
displayName: 'Operation',
|
||||||
name: "operation",
|
name: 'operation',
|
||||||
type: "options",
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: "Find",
|
name: 'Find',
|
||||||
value: "find",
|
value: 'find',
|
||||||
description: "Find documents.",
|
description: 'Find documents.'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Insert",
|
name: 'Insert',
|
||||||
value: "insert",
|
value: 'insert',
|
||||||
description: "Insert documents.",
|
description: 'Insert documents.'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Update",
|
name: 'Update',
|
||||||
value: "update",
|
value: 'update',
|
||||||
description: "Updates documents.",
|
description: 'Updates documents.'
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
default: "find",
|
default: 'find',
|
||||||
description: "The operation to perform.",
|
description: 'The operation to perform.'
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
displayName: "Collection",
|
displayName: 'Collection',
|
||||||
name: "collection",
|
name: 'collection',
|
||||||
type: "string",
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
default: "",
|
default: '',
|
||||||
description: "MongoDB Collection",
|
description: 'MongoDB Collection'
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// find
|
// find
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: "Query (JSON format)",
|
displayName: 'Query (JSON format)',
|
||||||
name: "query",
|
name: 'query',
|
||||||
type: "string",
|
type: 'string',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
rows: 5,
|
rows: 5
|
||||||
},
|
},
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ["find"],
|
operation: ['find']
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
default: '{}',
|
||||||
default: "{}",
|
|
||||||
placeholder: `{ "birth": { "$gt": "1950-01-01" } }`,
|
placeholder: `{ "birth": { "$gt": "1950-01-01" } }`,
|
||||||
required: true,
|
required: true,
|
||||||
description: "MongoDB Find query.",
|
description: 'MongoDB Find query.'
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// insert
|
// insert
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: "Fields",
|
displayName: 'Fields',
|
||||||
name: "fields",
|
name: 'fields',
|
||||||
type: "string",
|
type: 'string',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ["insert"],
|
operation: ['insert']
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
default: '',
|
||||||
default: "",
|
placeholder: 'name,description',
|
||||||
placeholder: "name,description",
|
|
||||||
description:
|
description:
|
||||||
"Comma separated list of the fields to be included into the new document.",
|
'Comma separated list of the fields to be included into the new document.'
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// update
|
// update
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: "Update Key",
|
displayName: 'Update Key',
|
||||||
name: "updateKey",
|
name: 'updateKey',
|
||||||
type: "string",
|
type: 'string',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ["update"],
|
operation: ['update']
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
default: 'id',
|
||||||
default: "id",
|
|
||||||
required: true,
|
required: true,
|
||||||
description:
|
description:
|
||||||
'Name of the property which decides which rows in the database should be updated. Normally that would be "id".',
|
'Name of the property which decides which rows in the database should be updated. Normally that would be "id".'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: "Fields",
|
displayName: 'Fields',
|
||||||
name: "fields",
|
name: 'fields',
|
||||||
type: "string",
|
type: 'string',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ["update"],
|
operation: ['update']
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
default: '',
|
||||||
default: "",
|
placeholder: 'name,description',
|
||||||
placeholder: "name,description",
|
|
||||||
description:
|
description:
|
||||||
"Comma separated list of the fields to be included into the new document.",
|
'Comma separated list of the fields to be included into the new document.'
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
ICredentialDataDecryptedObject,
|
ICredentialDataDecryptedObject
|
||||||
} from "n8n-workflow";
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard way of building the MongoDB connection string, unless overridden with a provided string
|
* Standard way of building the MongoDB connection string, unless overridden with a provided string
|
||||||
|
@ -33,7 +33,7 @@ export function getItemCopy(
|
||||||
): IDataObject[] {
|
): IDataObject[] {
|
||||||
// Prepare the data to insert and copy it to be returned
|
// Prepare the data to insert and copy it to be returned
|
||||||
let newItem: IDataObject;
|
let newItem: IDataObject;
|
||||||
return items.map((item) => {
|
return items.map(item => {
|
||||||
newItem = {};
|
newItem = {};
|
||||||
for (const property of properties) {
|
for (const property of properties) {
|
||||||
if (item.json[property] === undefined) {
|
if (item.json[property] === undefined) {
|
||||||
|
|
Loading…
Reference in a new issue