Added support for newer mongoose versions
-Mongoose and mongodb dependencies have been updated to the most recent versions in package.json -Updated the project for use with the newest mongoose major version which required fixing many breaking changes to a number of files in the explorer -Removed the db.find_address_tx() function as it is unused NOTE: This update requires mongoose 6.0.10 or higher. If you are getting errors running the explorer after upgrading, it is recommended to run an 'npm update' or manually update mongoose to a more modern version which should fix the problem
This commit is contained in:
+40
-41
@@ -52,12 +52,15 @@ function finishExit(db, exitCode) {
|
||||
|
||||
function drop_collection(mongoose, colName, cb) {
|
||||
// attempt to delete the collection
|
||||
mongoose.connection.db.dropCollection(colName, function(err, result) {
|
||||
if (err || !result) {
|
||||
mongoose.connection.db.dropCollection(colName).then((result) => {
|
||||
if (!result) {
|
||||
console.log(`Error: Unable to delete the ${colName} collection`);
|
||||
exit(mongoose, 1);
|
||||
} else
|
||||
return cb(true);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
exit(mongoose, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,49 +98,45 @@ rl.question('Are you sure you want to do this? [y/n]: ', function (deleteAnswer)
|
||||
mongoose.set('strictQuery', true);
|
||||
|
||||
// connect to mongo database
|
||||
mongoose.connect(dbString, function(err) {
|
||||
if (err) {
|
||||
console.log('Error: Unable to connect to database: %s', dbString);
|
||||
exit(mongoose, 999);
|
||||
} else {
|
||||
// get the list of collections
|
||||
mongoose.connection.db.listCollections().toArray(function (err, collections) {
|
||||
if (err) {
|
||||
console.log('Error: Unable to list collections in database: %s', err);
|
||||
exit(mongoose, 1);
|
||||
} else {
|
||||
// check if there are any collections
|
||||
if (collections.length > 0) {
|
||||
var counter = 0;
|
||||
mongoose.connect(dbString).then(() => {
|
||||
// get the list of collections
|
||||
mongoose.connection.db.listCollections().toArray().then((collections) => {
|
||||
// check if there are any collections
|
||||
if (collections.length > 0) {
|
||||
var counter = 0;
|
||||
|
||||
// loop through all collections
|
||||
collections.forEach((collection) => {
|
||||
console.log(`Deleting ${collection.name}..`);
|
||||
// loop through all collections
|
||||
collections.forEach((collection) => {
|
||||
console.log(`Deleting ${collection.name}..`);
|
||||
|
||||
// delete this collection
|
||||
drop_collection(mongoose, collection.name, function(retVal) {
|
||||
// check if the collection was successfully deleted
|
||||
if (retVal)
|
||||
counter++;
|
||||
// delete this collection
|
||||
drop_collection(mongoose, collection.name, function(retVal) {
|
||||
// check if the collection was successfully deleted
|
||||
if (retVal)
|
||||
counter++;
|
||||
|
||||
// check if the last collection was deleted
|
||||
if (counter == collections.length) {
|
||||
// finish the delete process
|
||||
console.log('Finished deleting database');
|
||||
exit(mongoose, 0);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// nothing to delete
|
||||
console.log('Nothing to delete, the database is already empty..');
|
||||
// check if the last collection was deleted
|
||||
if (counter == collections.length) {
|
||||
// finish the delete process
|
||||
console.log('Finished deleting database');
|
||||
exit(mongoose, 0);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// nothing to delete
|
||||
console.log('Nothing to delete, the database is already empty..');
|
||||
|
||||
// finish the delete process
|
||||
exit(mongoose, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// finish the delete process
|
||||
exit(mongoose, 0);
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log('Error: Unable to list collections in database: %s', err);
|
||||
exit(mongoose, 1);
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log('Error: Unable to connect to database: %s', err);
|
||||
exit(mongoose, 999);
|
||||
});
|
||||
} else {
|
||||
// another script process is currently running
|
||||
|
||||
Reference in New Issue
Block a user