File mongo_driver.js
has 1043 lines of code (exceeds 250 allowed). Consider refactoring. Open
import { normalizeProjection } from "./mongo_utils";
/**
* Provide a synchronous Collection API using fibers, backed by
* MongoDB. This is only for use on the server, and mostly identical
Function _update
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
MongoConnection.prototype._update = function (collection_name, selector, mod,
options, callback) {
var self = this;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _update
has 115 lines of code (exceeds 25 allowed). Consider refactoring. Open
MongoConnection.prototype._update = function (collection_name, selector, mod,
options, callback) {
var self = this;
Function _observeChanges
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
MongoConnection.prototype._observeChanges = function (
cursorDescription, ordered, callbacks, nonMutatingCallbacks) {
var self = this;
if (cursorDescription.options.tailable) {
Function tail
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
MongoConnection.prototype.tail = function (cursorDescription, docCallback, timeoutMS) {
var self = this;
if (!cursorDescription.options.tailable)
throw new Error("Can only tail a tailable cursor");
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function simulateUpsertWithInsertedId
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
var simulateUpsertWithInsertedId = function (collection, selector, mod,
options, callback) {
// STRATEGY: First try doing an upsert with a generated ID.
// If this throws an error about changing the ID on an existing document
// then without affecting the database, we know we should probably try
Function simulateUpsertWithInsertedId
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
var simulateUpsertWithInsertedId = function (collection, selector, mod,
options, callback) {
// STRATEGY: First try doing an upsert with a generated ID.
// If this throws an error about changing the ID on an existing document
// then without affecting the database, we know we should probably try
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function tail
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
MongoConnection.prototype.tail = function (cursorDescription, docCallback, timeoutMS) {
var self = this;
if (!cursorDescription.options.tailable)
throw new Error("Can only tail a tailable cursor");
Function writeCallback
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
var writeCallback = function (write, refresh, callback) {
return function (err, result) {
if (! err) {
// XXX We don't have to run this on error, right?
try {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _insert
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
MongoConnection.prototype._insert = function (collection_name, document,
callback) {
var self = this;
var sendError = function (e) {
Function _observeChanges
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
MongoConnection.prototype._observeChanges = function (
cursorDescription, ordered, callbacks, nonMutatingCallbacks) {
var self = this;
if (cursorDescription.options.tailable) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _createSynchronousCursor
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
MongoConnection.prototype._createSynchronousCursor = function(
cursorDescription, options) {
var self = this;
options = _.pick(options || {}, 'selfForIteration', 'useTransform');
Function _remove
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
MongoConnection.prototype._remove = function (collection_name, selector,
callback) {
var self = this;
if (collection_name === "___meteor_failure_test_collection") {
Function _nextObjectPromise
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
_nextObjectPromise: async function () {
var self = this;
while (true) {
var doc = await self._rawNextObjectPromise();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function loop
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
var loop = function () {
var doc = null;
while (true) {
if (stopped)
return;
Function doUpdate
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
var doUpdate = function () {
tries--;
if (! tries) {
callback(new Error("Upsert failed after " + NUM_OPTIMISTIC_TRIES + " tries."));
} else {
Consider simplifying this complex logical expression. Open
if (options.upsert &&
! isModify &&
! knownId &&
options.insertedId &&
! (options.insertedId instanceof Mongo.ObjectID &&
Function replaceMongoAtomWithMeteor
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
var replaceMongoAtomWithMeteor = function (document) {
if (document instanceof MongoDB.Binary) {
// for backwards compatibility
if (document.sub_type !== 0) {
return document;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function transformResult
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
var transformResult = function (driverResult) {
var meteorResult = { numberAffected: 0 };
if (driverResult) {
var mongoResult = driverResult.result;
// On updates with upsert:true, the inserted values come as a list of
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if (knownId) {
meteorResult.insertedId = knownId;
} else if (meteorResult.insertedId instanceof MongoDB.ObjectID) {
meteorResult.insertedId = new Mongo.ObjectID(meteorResult.insertedId.toHexString());
}
Function _update
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
MongoConnection.prototype._update = function (collection_name, selector, mod,
options, callback) {
Function upsert
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
MongoConnection.prototype.upsert = function (collectionName, selector, mod,
options, callback) {
Function simulateUpsertWithInsertedId
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
var simulateUpsertWithInsertedId = function (collection, selector, mod,
options, callback) {
Function _observeChangesTailable
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
MongoConnection.prototype._observeChangesTailable = function (
cursorDescription, ordered, callbacks) {
var self = this;
// Tailable cursors only ever call added/addedBefore callbacks, so it's an
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _createSynchronousCursor
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
MongoConnection.prototype._createSynchronousCursor = function(
cursorDescription, options) {
var self = this;
options = _.pick(options || {}, 'selfForIteration', 'useTransform');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return EJSON.fromJSONValue(replaceNames(unmakeMongoLegal, document));
Avoid too many return
statements within this function. Open
return replaceNames(makeMongoLegal, EJSON.toJSONValue(document));
Avoid too many return
statements within this function. Open
return document;
Avoid too many return
statements within this function. Open
return undefined;
Avoid too many return
statements within this function. Open
return MongoDB.Decimal128.fromString(document.toString());
Avoid too many return
statements within this function. Open
return undefined;
Function replaceMeteorAtomWithMongo
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
var replaceMeteorAtomWithMongo = function (document) {
if (EJSON.isBinary(document)) {
// This does more copies than we'd like, but is necessary because
// MongoDB.BSON only looks like it takes a Uint8Array (and doesn't actually
// serialize it correctly).
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _insert
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
MongoConnection.prototype._insert = function (collection_name, document,
callback) {
var self = this;
var sendError = function (e) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
MongoConnection.prototype.estimatedDocumentCount = function (collectionName, ...args) {
args = args.map(arg => replaceTypes(arg, replaceMeteorAtomWithMongo));
const collection = this.rawCollection(collectionName);
return collection.estimatedDocumentCount(...args);
};
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 76.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
MongoConnection.prototype.countDocuments = function (collectionName, ...args) {
args = args.map(arg => replaceTypes(arg, replaceMeteorAtomWithMongo));
const collection = this.rawCollection(collectionName);
return collection.countDocuments(...args);
};
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 76.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
SynchronousCursor.prototype[Symbol.asyncIterator] = function () {
const syncResult = this[Symbol.iterator]();
return {
async next() {
return Promise.resolve(syncResult.next());
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 52.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (collection_name === "___meteor_failure_test_collection") {
var e = new Error("Failure test");
e._expectedByTest = true;
if (callback) {
return callback(e);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 47.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (collection_name === "___meteor_failure_test_collection") {
var e = new Error("Failure test");
e._expectedByTest = true;
if (callback) {
return callback(e);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 47.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76