fix(MongoDB Node): Stringify response ObjectIDs (#6990)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Marcus
2023-08-29 17:44:37 +02:00
committed by GitHub
parent 8a01d063c9
commit 9ca990b993
4 changed files with 320 additions and 307 deletions

View File

@@ -6,15 +6,15 @@ import type {
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import get from 'lodash/get';
import set from 'lodash/set';
import { ObjectId } from 'mongodb';
import type {
IMongoCredentials,
IMongoCredentialsType,
IMongoParametricCredentials,
} from './mongoDb.types';
import get from 'lodash/get';
import set from 'lodash/set';
/**
* Standard way of building the MongoDB connection string, unless overridden with a provided string
*
@@ -129,3 +129,14 @@ export function prepareFields(fields: string) {
.map((field) => field.trim())
.filter((field) => !!field);
}
export function stringifyObjectIDs(items: IDataObject[]) {
items.forEach((item) => {
if (item._id instanceof ObjectId) {
item._id = item._id.toString();
}
if (item.id instanceof ObjectId) {
item.id = item.id.toString();
}
});
}