From 74924f8df5260192eb01d5c34f5050c253fe2d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Dias=20Moreira?= Date: Fri, 14 Sep 2018 15:42:42 -0300 Subject: [PATCH] fix circular reference between modules db.js and db_ops.js --- lib/db.js | 11 ++--------- lib/db_constants.js | 9 +++++++++ lib/operations/db_ops.js | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 lib/db_constants.js diff --git a/lib/db.js b/lib/db.js index 478989638e..c9619daa63 100644 --- a/lib/db.js +++ b/lib/db.js @@ -1,5 +1,6 @@ 'use strict'; +const dbConstants = require("./db_constants"); const EventEmitter = require('events').EventEmitter; const inherits = require('util').inherits; const getSingleProperty = require('./utils').getSingleProperty; @@ -532,7 +533,7 @@ Db.prototype.listCollections = function(filter, options) { // Return options const _options = { transforms: listCollectionsTransforms(this.s.databaseName) }; // Get the cursor - cursor = this.collection(Db.SYSTEM_NAMESPACE_COLLECTION).find(filter, _options); + cursor = this.collection(dbConstants.SYSTEM_NAMESPACE_COLLECTION).find(filter, _options); // Do we have a readPreference, apply it if (options.readPreference) cursor.setReadPreference(options.readPreference); // Set the passed in batch size if one was provided @@ -973,12 +974,4 @@ Db.prototype.getLogger = function() { * @type {Db} */ -// Constants -Db.SYSTEM_NAMESPACE_COLLECTION = 'system.namespaces'; -Db.SYSTEM_INDEX_COLLECTION = 'system.indexes'; -Db.SYSTEM_PROFILE_COLLECTION = 'system.profile'; -Db.SYSTEM_USER_COLLECTION = 'system.users'; -Db.SYSTEM_COMMAND_COLLECTION = '$cmd'; -Db.SYSTEM_JS_COLLECTION = 'system.js'; - module.exports = Db; diff --git a/lib/db_constants.js b/lib/db_constants.js new file mode 100644 index 0000000000..cf76e61ba9 --- /dev/null +++ b/lib/db_constants.js @@ -0,0 +1,9 @@ +'use strict'; + +// Constants +module.exports.SYSTEM_NAMESPACE_COLLECTION = 'system.namespaces'; +module.exports.SYSTEM_INDEX_COLLECTION = 'system.indexes'; +module.exports.SYSTEM_PROFILE_COLLECTION = 'system.profile'; +module.exports.SYSTEM_USER_COLLECTION = 'system.users'; +module.exports.SYSTEM_COMMAND_COLLECTION = '$cmd'; +module.exports.SYSTEM_JS_COLLECTION = 'system.js'; diff --git a/lib/operations/db_ops.js b/lib/operations/db_ops.js index af0210a97b..c43a196383 100644 --- a/lib/operations/db_ops.js +++ b/lib/operations/db_ops.js @@ -1,10 +1,10 @@ 'use strict'; +const dbConstants = require("../db_constants"); const applyWriteConcern = require('../utils').applyWriteConcern; const Code = require('mongodb-core').BSON.Code; const resolveReadPreference = require('../utils').resolveReadPreference; const crypto = require('crypto'); -const Db = require('../db'); const debugOptions = require('../utils').debugOptions; const handleCallback = require('../utils').handleCallback; const MongoError = require('mongodb-core').MongoError; @@ -83,7 +83,7 @@ function addUser(db, username, password, options, callback) { const db = options.dbName ? new Db(options.dbName, db.s.topology, db.s.options) : db; // Fetch a user collection - const collection = db.collection(Db.SYSTEM_USER_COLLECTION); + const collection = db.collection(dbConstants.SYSTEM_USER_COLLECTION); // Check if we are inserting the first user count(collection, {}, finalOptions, (err, count) => { @@ -296,7 +296,7 @@ function createIndex(db, name, fieldOrSpec, options, callback) { finalOptions.checkKeys = false; // Insert document db.s.topology.insert( - `${db.s.databaseName}.${Db.SYSTEM_INDEX_COLLECTION}`, + `${db.s.databaseName}.${dbConstants.SYSTEM_INDEX_COLLECTION}`, doc, finalOptions, (err, result) => { @@ -638,7 +638,7 @@ function removeUser(db, username, options, callback) { const db = options.dbName ? new Db(options.dbName, db.s.topology, db.s.options) : db; // Fetch a user collection - const collection = db.collection(Db.SYSTEM_USER_COLLECTION); + const collection = db.collection(dbConstants.SYSTEM_USER_COLLECTION); // Locate the user findOne(collection, { user: username }, finalOptions, (err, user) => {