mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add delete option to MongoDb-Node
This commit is contained in:
parent
75e96a35bb
commit
2af04e775d
|
@ -32,7 +32,18 @@ export class MongoDb implements INodeType {
|
||||||
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 === 'delete') {
|
||||||
|
// ----------------------------------
|
||||||
|
// delete
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
const { deletedCount } = await mdb
|
||||||
|
.collection(this.getNodeParameter('collection', 0) as string)
|
||||||
|
.deleteMany(JSON.parse(this.getNodeParameter('query', 0) as string));
|
||||||
|
|
||||||
|
returnItems = this.helpers.returnJsonArray([{ deletedCount }]);
|
||||||
|
|
||||||
|
} else if (operation === 'find') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// find
|
// find
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
|
@ -28,6 +28,11 @@ export const nodeDescription: INodeTypeDescription = {
|
||||||
name: 'operation',
|
name: 'operation',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Delete',
|
||||||
|
value: 'delete',
|
||||||
|
description: 'Delete documents.'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Find',
|
name: 'Find',
|
||||||
value: 'find',
|
value: 'find',
|
||||||
|
@ -57,13 +62,36 @@ export const nodeDescription: INodeTypeDescription = {
|
||||||
description: 'MongoDB Collection'
|
description: 'MongoDB Collection'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// delete
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Delete Query (JSON format)',
|
||||||
|
name: 'query',
|
||||||
|
type: 'json',
|
||||||
|
typeOptions: {
|
||||||
|
rows: 5
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'delete'
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '{}',
|
||||||
|
placeholder: `{ "birth": { "$gt": "1950-01-01" } }`,
|
||||||
|
required: true,
|
||||||
|
description: 'MongoDB Delete query.'
|
||||||
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// find
|
// find
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Query (JSON format)',
|
displayName: 'Query (JSON format)',
|
||||||
name: 'query',
|
name: 'query',
|
||||||
type: 'string',
|
type: 'json',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
rows: 5
|
rows: 5
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue