Skip to content

Commit

Permalink
:Zap: Add dot notation for date fields (Mongodb)
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 committed May 11, 2021
1 parent b47de28 commit 3b09e49
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import {
INodeExecutionData,
NodeOperationError,
} from 'n8n-workflow';

import {
IMongoCredentials,
IMongoCredentialsType,
IMongoParametricCredentials,
} from './mongo.node.types';

import {
get,
set,
} from 'lodash';

/**
* Standard way of building the MongoDB connection string, unless overridden with a provided string
*
Expand Down Expand Up @@ -111,9 +117,9 @@ export function getItemCopy(
export function handleDateFields(insertItems: IDataObject[], fields: string) {
const dateFields = (fields as string).split(',');
for (let i = 0; i < insertItems.length; i++) {
for (const key of Object.keys(insertItems[i])) {
if (dateFields.includes(key)) {
insertItems[i][key] = new Date(insertItems[i][key] as string);
for (const field of dateFields) {
if (get(insertItems[i], field) !== undefined) {
set(insertItems[i], field, new Date(get(insertItems[i], field) as string));
}
}
}
Expand Down

0 comments on commit 3b09e49

Please sign in to comment.