diff options
author | Maddie Zechar <mez2113@columbia.edu> | 2021-06-08 18:08:24 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-11 01:37:49 +0000 |
commit | 30725e9c2316bf28a79d15d681c6df897b93b11b (patch) | |
tree | e7a1ecc8998edf159eae5d927767c119d93783f1 | |
parent | 5e64d72ebb0b8cd8b7d13a0b7ad590c973161468 (diff) | |
download | mongo-30725e9c2316bf28a79d15d681c6df897b93b11b.tar.gz |
SERVER-57256: Add deprecation message for count command and direct reader to docs
-rw-r--r-- | jstests/noPassthrough/deprecated_count.js | 37 | ||||
-rw-r--r-- | src/mongo/db/commands/count_cmd.cpp | 11 |
2 files changed, 48 insertions, 0 deletions
diff --git a/jstests/noPassthrough/deprecated_count.js b/jstests/noPassthrough/deprecated_count.js new file mode 100644 index 00000000000..aafee4ca749 --- /dev/null +++ b/jstests/noPassthrough/deprecated_count.js @@ -0,0 +1,37 @@ +// The count command is deprecated in 5.0. +// +// In this test, we run the count command several times. +// We want to make sure that the deprecation warning message is only logged once despite +// the multiple invocations in an effort to not clutter the dev's console. +// More specifically, we expect to only log 1/127 of count() events. + +(function() { +"use strict"; +load("jstests/libs/log.js"); // For findMatchingLogLine, findMatchingLogLines + +jsTest.log('Test standalone'); +const standalone = MongoRunner.runMongod({}); +const dbName = 'test'; +const collName = "test_count_command_deprecation_messaging"; +const db = standalone.getDB(dbName); +const coll = db.getCollection(collName); + +coll.drop(); +var res = assert.commandWorked(db.runCommand({count: collName})); +assert.eq(0, res.n); +assert.commandWorked(coll.insert({i: 1})); +res = assert.commandWorked(db.runCommand({count: collName})); +assert.eq(1, res.n); +assert.commandWorked(coll.insert({i: 1})); +res = assert.commandWorked(db.runCommand({count: collName})); +assert.eq(2, res.n); + +const globalLogs = db.adminCommand({getLog: 'global'}); +const fieldMatcher = { + msg: + "The count command is deprecated. For more information, see https://docs.mongodb.com/manual/reference/method/db.collection.count/" +}; +const matchingLogLines = [...findMatchingLogLines(globalLogs.log, fieldMatcher)]; +assert.eq(matchingLogLines.length, 1, matchingLogLines); +MongoRunner.stopMongod(standalone); +})(); diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp index 2d4769c5f86..626a3669ae6 100644 --- a/src/mongo/db/commands/count_cmd.cpp +++ b/src/mongo/db/commands/count_cmd.cpp @@ -61,10 +61,14 @@ using std::unique_ptr; // Failpoint which causes to hang "count" cmd after acquiring the DB lock. MONGO_FAIL_POINT_DEFINE(hangBeforeCollectionCount); +// The count command is deprecated in 5.0 + /** * Implements the MongoD side of the count command. */ class CmdCount : public BasicCommand { + inline static Rarely _sampler; + public: CmdCount() : BasicCommand("count") {} @@ -214,6 +218,13 @@ public: const string& dbname, const BSONObj& cmdObj, BSONObjBuilder& result) override { + + if (_sampler.tick()) { + LOGV2_WARNING(5725601, + "The count command is deprecated. For more information, see " + "https://docs.mongodb.com/manual/reference/method/db.collection.count/"); + } + CommandHelpers::handleMarkKillOnClientDisconnect(opCtx); // Acquire locks and resolve possible UUID. The RAII object is optional, because in the case // of a view, the locks need to be released. |