Initial commit
This commit is contained in:
32
node_modules/mongodb/lib/operations/find_one_and_update.js
generated
vendored
Normal file
32
node_modules/mongodb/lib/operations/find_one_and_update.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const FindAndModifyOperation = require('./find_and_modify');
|
||||
const hasAtomicOperators = require('../utils').hasAtomicOperators;
|
||||
|
||||
class FindOneAndUpdateOperation extends FindAndModifyOperation {
|
||||
constructor(collection, filter, update, options) {
|
||||
// Final options
|
||||
const finalOptions = Object.assign({}, options);
|
||||
finalOptions.fields = options.projection;
|
||||
finalOptions.update = true;
|
||||
finalOptions.new =
|
||||
typeof options.returnOriginal === 'boolean' ? !options.returnOriginal : false;
|
||||
finalOptions.upsert = typeof options.upsert === 'boolean' ? options.upsert : false;
|
||||
|
||||
if (filter == null || typeof filter !== 'object') {
|
||||
throw new TypeError('Filter parameter must be an object');
|
||||
}
|
||||
|
||||
if (update == null || typeof update !== 'object') {
|
||||
throw new TypeError('Update parameter must be an object');
|
||||
}
|
||||
|
||||
if (!hasAtomicOperators(update)) {
|
||||
throw new TypeError('Update document requires atomic operators');
|
||||
}
|
||||
|
||||
super(collection, filter, finalOptions.sort, update, finalOptions);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FindOneAndUpdateOperation;
|
||||
Reference in New Issue
Block a user