mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 05:36:00 +00:00
SYNC: mognodb - correct handle stream errors
This commit is contained in:
committed by
Diflow
parent
2b7f4281c2
commit
ba0eba7132
@@ -1,10 +1,9 @@
|
||||
const ObjectId = require('mongodb').ObjectId;
|
||||
const { getLogger } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
const { getLogger, extractErrorLogData } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
const { EJSON } = require('bson');
|
||||
|
||||
const logger = getLogger('mongoBulkInsert');
|
||||
|
||||
|
||||
function createBulkInsertStream(driver, stream, dbhan, name, options) {
|
||||
const collectionName = name.pureName;
|
||||
const db = dbhan.getDatabase();
|
||||
@@ -31,21 +30,31 @@ function createBulkInsertStream(driver, stream, dbhan, name, options) {
|
||||
};
|
||||
|
||||
writable.checkStructure = async () => {
|
||||
if (options.dropIfExists) {
|
||||
logger.info(`Dropping collection ${collectionName}`);
|
||||
await db.collection(collectionName).drop();
|
||||
}
|
||||
if (options.truncate) {
|
||||
logger.info(`Truncating collection ${collectionName}`);
|
||||
await db.collection(collectionName).deleteMany({});
|
||||
try {
|
||||
if (options.dropIfExists) {
|
||||
logger.info(`Dropping collection ${collectionName}`);
|
||||
await db.collection(collectionName).drop();
|
||||
}
|
||||
if (options.truncate) {
|
||||
logger.info(`Truncating collection ${collectionName}`);
|
||||
await db.collection(collectionName).deleteMany({});
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(extractErrorLogData(err), 'Error during preparing mongo bulk insert collection, stopped');
|
||||
writable.destroy(err);
|
||||
}
|
||||
};
|
||||
|
||||
writable.send = async () => {
|
||||
const rows = writable.buffer;
|
||||
writable.buffer = [];
|
||||
try {
|
||||
const rows = writable.buffer;
|
||||
writable.buffer = [];
|
||||
|
||||
await db.collection(collectionName).insertMany(rows);
|
||||
await db.collection(collectionName).insertMany(rows);
|
||||
} catch (err) {
|
||||
logger.error(extractErrorLogData(err), 'Error bulk insert collection, stopped');
|
||||
writable.destroy(err);
|
||||
}
|
||||
};
|
||||
|
||||
writable.sendIfFull = async () => {
|
||||
|
||||
Reference in New Issue
Block a user