@@ -1,7 +1,7 @@
|
||||
/* eslint-disable no-use-before-define */
|
||||
|
||||
import {
|
||||
assign,
|
||||
set,
|
||||
each,
|
||||
isEmpty,
|
||||
times,
|
||||
@@ -277,16 +277,23 @@ function _updateDocument (collectionName, doc, update, cb) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
// TODO use config for db url?
|
||||
mongo.connect('mongodb://localhost/habitrpg_test', (connectErr, db) => {
|
||||
if (connectErr) throw new Error(`Error connecting to database when updating ${collectionName} collection: ${connectErr}`);
|
||||
|
||||
let collection = db.collection(collectionName);
|
||||
|
||||
collection.update({ _id: doc._id }, { $set: update }, (updateErr) => {
|
||||
collection.updateOne({ _id: doc._id }, { $set: update }, (updateErr) => {
|
||||
if (updateErr) throw new Error(`Error updating ${collectionName}: ${updateErr}`);
|
||||
assign(doc, update);
|
||||
_updateLocalDocument(doc, update);
|
||||
db.close();
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function _updateLocalDocument (doc, update) {
|
||||
each(update, (value, param) => {
|
||||
set(doc, param, value);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user