diff --git a/packages/editor-ui/src/components/CredentialsInput.vue b/packages/editor-ui/src/components/CredentialsInput.vue
index 0830b2a2a..064d88fc7 100644
--- a/packages/editor-ui/src/components/CredentialsInput.vue
+++ b/packages/editor-ui/src/components/CredentialsInput.vue
@@ -21,18 +21,20 @@
-
-
- {{parameter.displayName}}:
-
-
-
-
-
-
-
-
-
+
+
+
+ {{parameter.displayName}}:
+
+
+
+
+
+
+
+
+
+
@@ -85,6 +87,7 @@ import {
ICredentialType,
ICredentialNodeAccess,
INodeCredentialDescription,
+ INodeProperties,
INodeTypeDescription,
} from 'n8n-workflow';
@@ -162,6 +165,14 @@ export default mixins(
tempValue[name] = parameterData.value;
Vue.set(this, 'propertyValue', tempValue);
},
+ displayCredentialParameter (parameter: INodeProperties): boolean {
+ if (parameter.displayOptions === undefined) {
+ // If it is not defined no need to do a proper check
+ return true;
+ }
+
+ return this.displayParameter(this.propertyValue, parameter, '');
+ },
async createCredentials (): Promise {
const nodesAccess = this.nodesAccess.map((nodeType) => {
return {
diff --git a/packages/nodes-base/credentials/MongoDb.credentials.ts b/packages/nodes-base/credentials/MongoDb.credentials.ts
index 436e9f2e4..a6de30217 100644
--- a/packages/nodes-base/credentials/MongoDb.credentials.ts
+++ b/packages/nodes-base/credentials/MongoDb.credentials.ts
@@ -4,10 +4,53 @@ export class MongoDb implements ICredentialType {
name = 'mongoDb';
displayName = 'MongoDB';
properties = [
+ {
+ displayName: 'Configuration Type',
+ name: 'configurationType',
+ type: 'options' as NodePropertyTypes,
+ options: [
+ {
+ name: 'Connection String',
+ value: 'connectionString',
+ description: 'Provide connection data via string',
+ },
+ {
+ name: 'Values',
+ value: 'values',
+ description: 'Provide connection data via values',
+ },
+ ],
+ default: 'values',
+ description: 'The operation to perform.',
+ },
+ {
+ displayName: 'Connection String',
+ name: 'connectionString',
+ type: 'string' as NodePropertyTypes,
+ displayOptions: {
+ show: {
+ configurationType: [
+ 'connectionString',
+ ],
+ },
+ },
+ default: '',
+ placeholder: 'mongodb://:@localhost:27017/?authSource=admin&readPreference=primary&appname=n8n&ssl=false',
+ required: false,
+ description: `If provided, the value here will be used as a MongoDB connection string,
+ and the MongoDB credentials will be ignored`
+ },
{
displayName: 'Host',
name: 'host',
type: 'string' as NodePropertyTypes,
+ displayOptions: {
+ show: {
+ configurationType: [
+ 'values',
+ ],
+ },
+ },
default: 'localhost'
},
{
@@ -15,13 +58,19 @@ export class MongoDb implements ICredentialType {
name: 'database',
type: 'string' as NodePropertyTypes,
default: '',
- description:
- 'Note: the database should still be provided even if using an override connection string'
+ description: 'Note: the database should still be provided even if using an override connection string'
},
{
displayName: 'User',
name: 'user',
type: 'string' as NodePropertyTypes,
+ displayOptions: {
+ show: {
+ configurationType: [
+ 'values',
+ ],
+ },
+ },
default: ''
},
{
@@ -31,34 +80,27 @@ export class MongoDb implements ICredentialType {
typeOptions: {
password: true
},
+ displayOptions: {
+ show: {
+ configurationType: [
+ 'values',
+ ],
+ },
+ },
default: ''
},
{
displayName: 'Port',
name: 'port',
type: 'number' as NodePropertyTypes,
+ displayOptions: {
+ show: {
+ configurationType: [
+ 'values',
+ ],
+ },
+ },
default: 27017
},
- {
- displayName: 'Override conn string',
- name: 'shouldOverrideConnString',
- type: 'boolean' as NodePropertyTypes,
- default: false,
- required: false,
- description:
- 'Whether to override the generated connection string. Credentials will also be ignored in this case.'
- },
- {
- displayName: 'Conn string override',
- name: 'connStringOverrideVal',
- type: 'string' as NodePropertyTypes,
- typeOptions: {
- rows: 1
- },
- default: '',
- placeholder: `mongodb://USERNAMEHERE:PASSWORDHERE@localhost:27017/?authSource=admin&readPreference=primary&appname=n8n&ssl=false`,
- required: false,
- description: `If provided, the value here will be used as a MongoDB connection string, and the MongoDB credentials will be ignored`
- }
];
}
diff --git a/packages/nodes-base/nodes/MongoDb/mongo.node.types.ts b/packages/nodes-base/nodes/MongoDb/mongo.node.types.ts
index 2995fdd2a..212ebc159 100644
--- a/packages/nodes-base/nodes/MongoDb/mongo.node.types.ts
+++ b/packages/nodes-base/nodes/MongoDb/mongo.node.types.ts
@@ -7,7 +7,8 @@ export interface IMongoParametricCredentials {
/**
* Whether to allow overriding the parametric credentials with a connection string
*/
- shouldOverrideConnString: false | undefined | null;
+ configurationType: 'values';
+
host: string;
database: string;
user: string;
@@ -22,11 +23,11 @@ export interface IMongoOverrideCredentials {
/**
* Whether to allow overriding the parametric credentials with a connection string
*/
- shouldOverrideConnString: true;
+ configurationType: 'connectionString';
/**
* If using an override connection string, this is where it will be.
*/
- connStringOverrideVal: string;
+ connectionString: string;
database: string;
}
diff --git a/packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts b/packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts
index 1d682a450..17ccc0dc4 100644
--- a/packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts
+++ b/packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts
@@ -37,13 +37,13 @@ function buildMongoConnectionParams(
credentials.database && credentials.database.trim().length > 0
? credentials.database.trim()
: '';
- if (credentials.shouldOverrideConnString) {
+ if (credentials.configurationType === 'connectionString') {
if (
- credentials.connStringOverrideVal &&
- credentials.connStringOverrideVal.trim().length > 0
+ credentials.connectionString &&
+ credentials.connectionString.trim().length > 0
) {
return {
- connectionString: credentials.connStringOverrideVal.trim(),
+ connectionString: credentials.connectionString.trim(),
database: sanitizedDbName
};
} else {
@@ -67,11 +67,11 @@ function buildMongoConnectionParams(
export function validateAndResolveMongoCredentials(
credentials?: ICredentialDataDecryptedObject
): IMongoCredentials {
- if (credentials == undefined) {
+ if (credentials === undefined) {
throw new Error('No credentials got returned!');
} else {
return buildMongoConnectionParams(
- (credentials as any) as IMongoCredentialsType
+ credentials as unknown as IMongoCredentialsType,
);
}
}