I would like to use findAndModify to atomically increment a field, using Mongoose.
However, the code below throws the error \"TypeError: Object # has no method \'fin
Taking the above response from @furf, this is my promised
solution:
// eslint-disable-next-line func-names
localeTypesSchema.statics.findAndModify = function (query, sort, update, opts, callback) {
const cb = callback || (() => { });
try {
const result = this.collection.findAndModify(query || {}, sort || [], update || {}, opts);
cb(null, result);
return Promise.resolve(result);
} catch (err) {
cb(err);
return Promise.reject(err);
}
};