2021-03-10 08:01:03 -08:00
|
|
|
import {
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
2020-04-05 18:06:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Options to be displayed
|
|
|
|
*/
|
|
|
|
export const nodeDescription: INodeTypeDescription = {
|
2020-04-06 11:04:59 -07:00
|
|
|
displayName: 'MongoDB',
|
|
|
|
name: 'mongoDb',
|
2021-03-12 02:45:50 -08:00
|
|
|
icon: 'file:mongodb.svg',
|
2020-04-06 11:04:59 -07:00
|
|
|
group: ['input'],
|
2020-04-05 18:06:00 -07:00
|
|
|
version: 1,
|
2021-07-03 05:40:16 -07:00
|
|
|
description: 'Find, insert and update documents in MongoDB',
|
2020-04-05 18:06:00 -07:00
|
|
|
defaults: {
|
2020-04-06 11:04:59 -07:00
|
|
|
name: 'MongoDB',
|
2020-10-22 06:46:03 -07:00
|
|
|
color: '#13AA52',
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
2020-04-06 11:04:59 -07:00
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
2020-04-05 18:06:00 -07:00
|
|
|
credentials: [
|
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
name: 'mongoDb',
|
2020-10-22 06:46:03 -07:00
|
|
|
required: true,
|
|
|
|
},
|
2020-04-05 18:06:00 -07:00
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
2020-04-05 18:06:00 -07:00
|
|
|
options: [
|
2020-06-13 10:22:49 -07:00
|
|
|
{
|
|
|
|
name: 'Delete',
|
|
|
|
value: 'delete',
|
2020-10-22 06:46:03 -07:00
|
|
|
description: 'Delete documents.',
|
2020-06-13 10:22:49 -07:00
|
|
|
},
|
2020-04-05 18:06:00 -07:00
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
name: 'Find',
|
|
|
|
value: 'find',
|
2020-10-22 06:46:03 -07:00
|
|
|
description: 'Find documents.',
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
name: 'Insert',
|
|
|
|
value: 'insert',
|
2020-10-22 06:46:03 -07:00
|
|
|
description: 'Insert documents.',
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
name: 'Update',
|
|
|
|
value: 'update',
|
2021-03-10 08:01:03 -08:00
|
|
|
description: 'Update documents.',
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-04-05 18:06:00 -07:00
|
|
|
],
|
2020-04-06 11:04:59 -07:00
|
|
|
default: 'find',
|
2020-10-22 06:46:03 -07:00
|
|
|
description: 'The operation to perform.',
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
displayName: 'Collection',
|
|
|
|
name: 'collection',
|
|
|
|
type: 'string',
|
2020-04-05 18:06:00 -07:00
|
|
|
required: true,
|
2020-04-06 11:04:59 -07:00
|
|
|
default: '',
|
2020-10-22 06:46:03 -07:00
|
|
|
description: 'MongoDB Collection',
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
|
|
|
|
2020-06-13 10:22:49 -07:00
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
|
|
|
{
|
|
|
|
displayName: 'Delete Query (JSON format)',
|
|
|
|
name: 'query',
|
|
|
|
type: 'json',
|
|
|
|
typeOptions: {
|
2020-10-22 06:46:03 -07:00
|
|
|
rows: 5,
|
2020-06-13 10:22:49 -07:00
|
|
|
},
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
2020-10-22 06:46:03 -07:00
|
|
|
'delete',
|
2020-06-13 10:22:49 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '{}',
|
|
|
|
placeholder: `{ "birth": { "$gt": "1950-01-01" } }`,
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
description: 'MongoDB Delete query.',
|
2020-06-13 10:22:49 -07:00
|
|
|
},
|
|
|
|
|
2020-04-05 18:06:00 -07:00
|
|
|
// ----------------------------------
|
|
|
|
// find
|
|
|
|
// ----------------------------------
|
2021-04-14 04:41:56 -07:00
|
|
|
{
|
|
|
|
displayName: 'Options',
|
|
|
|
name: 'options',
|
|
|
|
type: 'collection',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: ['find'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: {},
|
|
|
|
placeholder: 'Add options',
|
|
|
|
description: 'Add query options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
displayName: 'Limit',
|
|
|
|
name: 'limit',
|
2021-04-14 05:04:59 -07:00
|
|
|
type: 'number',
|
2021-04-14 04:41:56 -07:00
|
|
|
default: 0,
|
|
|
|
description: 'Use limit to specify the maximum number of documents or 0 for unlimited documents.',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Skip',
|
|
|
|
name: 'skip',
|
2021-04-14 05:04:59 -07:00
|
|
|
type: 'number',
|
2021-04-14 04:41:56 -07:00
|
|
|
default: 0,
|
|
|
|
description: 'The number of documents to skip in the results set.',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Sort (JSON format)',
|
|
|
|
name: 'sort',
|
|
|
|
type: 'json',
|
|
|
|
typeOptions: {
|
|
|
|
rows: 2,
|
|
|
|
},
|
|
|
|
default: '{}',
|
|
|
|
placeholder: '{ "field": -1 }',
|
|
|
|
required: true,
|
|
|
|
description: 'A json that defines the sort order of the result set.',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-04-05 18:06:00 -07:00
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
displayName: 'Query (JSON format)',
|
|
|
|
name: 'query',
|
2020-06-13 10:22:49 -07:00
|
|
|
type: 'json',
|
2020-04-05 18:06:00 -07:00
|
|
|
typeOptions: {
|
2020-10-22 06:46:03 -07:00
|
|
|
rows: 5,
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2021-03-10 08:01:03 -08:00
|
|
|
operation: [
|
|
|
|
'find',
|
|
|
|
],
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
2020-04-06 11:04:59 -07:00
|
|
|
default: '{}',
|
2020-04-05 18:06:00 -07:00
|
|
|
placeholder: `{ "birth": { "$gt": "1950-01-01" } }`,
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
description: 'MongoDB Find query.',
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
|
|
|
// ----------------------------------
|
|
|
|
// insert
|
|
|
|
// ----------------------------------
|
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
displayName: 'Fields',
|
|
|
|
name: 'fields',
|
|
|
|
type: 'string',
|
2020-04-05 18:06:00 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2021-03-10 08:01:03 -08:00
|
|
|
operation: [
|
|
|
|
'insert',
|
|
|
|
],
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
2020-04-06 11:04:59 -07:00
|
|
|
default: '',
|
|
|
|
placeholder: 'name,description',
|
2020-04-05 18:06:00 -07:00
|
|
|
description:
|
2020-10-22 06:46:03 -07:00
|
|
|
'Comma separated list of the fields to be included into the new document.',
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
displayName: 'Update Key',
|
|
|
|
name: 'updateKey',
|
|
|
|
type: 'string',
|
2020-04-05 18:06:00 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2021-03-10 08:01:03 -08:00
|
|
|
operation: [
|
|
|
|
'update',
|
|
|
|
],
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
2020-04-06 11:04:59 -07:00
|
|
|
default: 'id',
|
2020-04-05 18:06:00 -07:00
|
|
|
required: true,
|
|
|
|
description:
|
2020-10-22 06:46:03 -07:00
|
|
|
'Name of the property which decides which rows in the database should be updated. Normally that would be "id".',
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
|
|
|
{
|
2020-04-06 11:04:59 -07:00
|
|
|
displayName: 'Fields',
|
|
|
|
name: 'fields',
|
|
|
|
type: 'string',
|
2020-04-05 18:06:00 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2021-03-10 08:01:03 -08:00
|
|
|
operation: [
|
|
|
|
'update',
|
|
|
|
],
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-04-05 18:06:00 -07:00
|
|
|
},
|
2020-04-06 11:04:59 -07:00
|
|
|
default: '',
|
|
|
|
placeholder: 'name,description',
|
2020-04-05 18:06:00 -07:00
|
|
|
description:
|
2020-10-22 06:46:03 -07:00
|
|
|
'Comma separated list of the fields to be included into the new document.',
|
|
|
|
},
|
2021-04-14 04:41:56 -07:00
|
|
|
{
|
|
|
|
displayName: 'Upsert',
|
|
|
|
name: 'upsert',
|
|
|
|
type: 'boolean',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: ['update'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: false,
|
|
|
|
description: `Perform an insert if no documents match the update key`,
|
|
|
|
},
|
2021-03-10 08:01:03 -08:00
|
|
|
{
|
|
|
|
displayName: 'Options',
|
|
|
|
name: 'options',
|
|
|
|
type: 'collection',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'update',
|
|
|
|
'insert',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
placeholder: 'Add Option',
|
|
|
|
default: {},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
displayName: 'Date Fields',
|
|
|
|
name: 'dateFields',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
description: 'Comma separeted list of fields that will be parse as Mongo Date type.',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2020-04-05 18:06:00 -07:00
|
|
|
};
|