MongoDB TextEncoder is not defined fix (#4499)

This commit is contained in:
Ylian Saint-Hilaire 2022-09-05 01:40:43 -07:00
parent 77405a7232
commit 43abf32dba

5
db.js
View File

@ -828,6 +828,11 @@ module.exports.CreateDB = function (parent, func) {
} else if (parent.args.mongodb) {
// Use MongoDB
obj.databaseType = 3;
// If running an older NodeJS version, TextEncoder/TextDecoder is required
if (global.TextEncoder == null) { global.TextEncoder = require('util').TextEncoder; }
if (global.TextDecoder == null) { global.TextDecoder = require('util').TextDecoder; }
require('mongodb').MongoClient.connect(parent.args.mongodb, { useNewUrlParser: true, useUnifiedTopology: true }, function (err, client) {
if (err != null) { console.log("Unable to connect to database: " + err); process.exit(); return; }
Datastore = client;