Refactoring day1
This commit is contained in:
23
node_modules/mongodb/lib/operations/collection_ops.js
generated
vendored
23
node_modules/mongodb/lib/operations/collection_ops.js
generated
vendored
@@ -8,11 +8,13 @@ const decorateWithReadConcern = require('../utils').decorateWithReadConcern;
|
||||
const ensureIndexDb = require('./db_ops').ensureIndex;
|
||||
const evaluate = require('./db_ops').evaluate;
|
||||
const executeCommand = require('./db_ops').executeCommand;
|
||||
const resolveReadPreference = require('../utils').resolveReadPreference;
|
||||
const handleCallback = require('../utils').handleCallback;
|
||||
const indexInformationDb = require('./db_ops').indexInformation;
|
||||
const Long = require('../core').BSON.Long;
|
||||
const MongoError = require('../core').MongoError;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const toError = require('../utils').toError;
|
||||
const insertDocuments = require('./common_functions').insertDocuments;
|
||||
const updateDocuments = require('./common_functions').updateDocuments;
|
||||
|
||||
@@ -50,6 +52,24 @@ const updateDocuments = require('./common_functions').updateDocuments;
|
||||
const groupFunction =
|
||||
'function () {\nvar c = db[ns].find(condition);\nvar map = new Map();\nvar reduce_function = reduce;\n\nwhile (c.hasNext()) {\nvar obj = c.next();\nvar key = {};\n\nfor (var i = 0, len = keys.length; i < len; ++i) {\nvar k = keys[i];\nkey[k] = obj[k];\n}\n\nvar aggObj = map.get(key);\n\nif (aggObj == null) {\nvar newObj = Object.extend({}, key);\naggObj = Object.extend(newObj, initial);\nmap.put(key, aggObj);\n}\n\nreduce_function(obj, aggObj);\n}\n\nreturn { "result": map.values() };\n}';
|
||||
|
||||
// Check the update operation to ensure it has atomic operators.
|
||||
function checkForAtomicOperators(update) {
|
||||
if (Array.isArray(update)) {
|
||||
return update.reduce((err, u) => err || checkForAtomicOperators(u), null);
|
||||
}
|
||||
|
||||
const keys = Object.keys(update);
|
||||
|
||||
// same errors as the server would give for update doc lacking atomic operators
|
||||
if (keys.length === 0) {
|
||||
return toError('The update operation document must contain at least one atomic operator.');
|
||||
}
|
||||
|
||||
if (keys[0][0] !== '$') {
|
||||
return toError('the update operation document must contain atomic operators.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an index on the db and collection.
|
||||
*
|
||||
@@ -168,7 +188,7 @@ function group(coll, keys, condition, initial, reduce, finalize, command, option
|
||||
|
||||
options = Object.assign({}, options);
|
||||
// Ensure we have the right read preference inheritance
|
||||
options.readPreference = ReadPreference.resolve(coll, options);
|
||||
options.readPreference = resolveReadPreference(coll, options);
|
||||
|
||||
// Do we have a readConcern specified
|
||||
decorateWithReadConcern(selector, coll, options);
|
||||
@@ -341,6 +361,7 @@ function save(coll, doc, options, callback) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkForAtomicOperators,
|
||||
createIndex,
|
||||
createIndexes,
|
||||
ensureIndex,
|
||||
|
||||
Reference in New Issue
Block a user