mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
fix(MongoDb Node): update mongo driver to 4.9.1 n8n-2622 (#4095)
This commit is contained in:
parent
fd9b5f6b2b
commit
f70e6d2345
|
@ -11,7 +11,7 @@ import {
|
|||
IMongoCredentials,
|
||||
IMongoCredentialsType,
|
||||
IMongoParametricCredentials,
|
||||
} from './mongo.node.types';
|
||||
} from './mongoDb.types';
|
||||
|
||||
import { get, set } from 'lodash';
|
||||
|
|
@ -12,15 +12,15 @@ import {
|
|||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { nodeDescription } from './mongo.node.options';
|
||||
import { nodeDescription } from './MongoDbDescription';
|
||||
|
||||
import { buildParameterizedConnString, prepareFields, prepareItems } from './mongo.node.utils';
|
||||
import { buildParameterizedConnString, prepareFields, prepareItems } from './GenericFunctions';
|
||||
|
||||
import { MongoClient, ObjectID } from 'mongodb';
|
||||
import { FindOneAndReplaceOptions, FindOneAndUpdateOptions, MongoClient, ObjectId, UpdateOptions } from 'mongodb';
|
||||
|
||||
import { validateAndResolveMongoCredentials } from './mongo.node.utils';
|
||||
import { validateAndResolveMongoCredentials } from './GenericFunctions';
|
||||
|
||||
import { IMongoParametricCredentials } from './mongo.node.types';
|
||||
import { IMongoParametricCredentials } from './mongoDb.types';
|
||||
|
||||
export class MongoDb implements INodeType {
|
||||
description: INodeTypeDescription = nodeDescription;
|
||||
|
@ -32,6 +32,7 @@ export class MongoDb implements INodeType {
|
|||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data as IDataObject;
|
||||
|
||||
try {
|
||||
const database = ((credentials.database as string) || '').trim();
|
||||
let connectionString = '';
|
||||
|
@ -44,10 +45,7 @@ export class MongoDb implements INodeType {
|
|||
);
|
||||
}
|
||||
|
||||
const client: MongoClient = await MongoClient.connect(connectionString, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
const client: MongoClient = await MongoClient.connect(connectionString);
|
||||
|
||||
const { databases } = await client.db().admin().listDatabases();
|
||||
|
||||
|
@ -76,10 +74,7 @@ export class MongoDb implements INodeType {
|
|||
await this.getCredentials('mongoDb'),
|
||||
);
|
||||
|
||||
const client: MongoClient = await MongoClient.connect(connectionString, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
const client: MongoClient = await MongoClient.connect(connectionString);
|
||||
|
||||
const mdb = client.db(database as string);
|
||||
|
||||
|
@ -98,7 +93,7 @@ export class MongoDb implements INodeType {
|
|||
const queryParameter = JSON.parse(this.getNodeParameter('query', 0) as string);
|
||||
|
||||
if (queryParameter._id && typeof queryParameter._id === 'string') {
|
||||
queryParameter._id = new ObjectID(queryParameter._id);
|
||||
queryParameter._id = new ObjectId(queryParameter._id);
|
||||
}
|
||||
|
||||
const query = mdb
|
||||
|
@ -140,7 +135,7 @@ export class MongoDb implements INodeType {
|
|||
const queryParameter = JSON.parse(this.getNodeParameter('query', 0) as string);
|
||||
|
||||
if (queryParameter._id && typeof queryParameter._id === 'string') {
|
||||
queryParameter._id = new ObjectID(queryParameter._id);
|
||||
queryParameter._id = new ObjectId(queryParameter._id);
|
||||
}
|
||||
|
||||
let query = mdb
|
||||
|
@ -193,13 +188,13 @@ export class MongoDb implements INodeType {
|
|||
try {
|
||||
const filter = { [updateKey]: item[updateKey] };
|
||||
if (updateKey === '_id') {
|
||||
filter[updateKey] = new ObjectID(item[updateKey] as string);
|
||||
filter[updateKey] = new ObjectId(item[updateKey] as string);
|
||||
delete item['_id'];
|
||||
}
|
||||
|
||||
await mdb
|
||||
.collection(this.getNodeParameter('collection', 0) as string)
|
||||
.findOneAndReplace(filter, item, updateOptions);
|
||||
.findOneAndReplace(filter, item, updateOptions as FindOneAndReplaceOptions);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
item.json = { error: (error as JsonObject).message };
|
||||
|
@ -233,13 +228,13 @@ export class MongoDb implements INodeType {
|
|||
try {
|
||||
const filter = { [updateKey]: item[updateKey] };
|
||||
if (updateKey === '_id') {
|
||||
filter[updateKey] = new ObjectID(item[updateKey] as string);
|
||||
filter[updateKey] = new ObjectId(item[updateKey] as string);
|
||||
delete item['_id'];
|
||||
}
|
||||
|
||||
await mdb
|
||||
.collection(this.getNodeParameter('collection', 0) as string)
|
||||
.findOneAndUpdate(filter, { $set: item }, updateOptions);
|
||||
.findOneAndUpdate(filter, { $set: item }, updateOptions as FindOneAndUpdateOptions);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
item.json = { error: (error as JsonObject).message };
|
||||
|
@ -272,7 +267,7 @@ export class MongoDb implements INodeType {
|
|||
for (const i of Object.keys(insertedIds)) {
|
||||
responseData.push({
|
||||
...insertItems[parseInt(i, 10)],
|
||||
id: insertedIds[parseInt(i, 10)] as string,
|
||||
id: insertedIds[parseInt(i, 10)] as unknown as string,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -305,13 +300,13 @@ export class MongoDb implements INodeType {
|
|||
try {
|
||||
const filter = { [updateKey]: item[updateKey] };
|
||||
if (updateKey === '_id') {
|
||||
filter[updateKey] = new ObjectID(item[updateKey] as string);
|
||||
filter[updateKey] = new ObjectId(item[updateKey] as string);
|
||||
delete item['_id'];
|
||||
}
|
||||
|
||||
await mdb
|
||||
.collection(this.getNodeParameter('collection', 0) as string)
|
||||
.updateOne(filter, { $set: item }, updateOptions);
|
||||
.updateOne(filter, { $set: item }, updateOptions as UpdateOptions);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
item.json = { error: (error as JsonObject).message };
|
||||
|
|
|
@ -719,7 +719,6 @@
|
|||
"@types/mailparser": "^2.7.3",
|
||||
"@types/mime-types": "^2.1.0",
|
||||
"@types/moment-timezone": "^0.5.12",
|
||||
"@types/mongodb": "^3.5.4",
|
||||
"@types/mqtt": "^2.5.0",
|
||||
"@types/mssql": "^6.0.2",
|
||||
"@types/node": "^16.11.22",
|
||||
|
@ -770,7 +769,7 @@
|
|||
"mailparser": "^3.2.0",
|
||||
"moment": "~2.29.2",
|
||||
"moment-timezone": "^0.5.28",
|
||||
"mongodb": "^3.6.9",
|
||||
"mongodb": "^4.9.1",
|
||||
"mqtt": "4.2.6",
|
||||
"mssql": "^8.1.2",
|
||||
"mysql2": "~2.3.0",
|
||||
|
|
Loading…
Reference in a new issue