summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMaddie Zechar <mez2113@columbia.edu>2021-06-08 18:08:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-11 01:37:49 +0000
commit30725e9c2316bf28a79d15d681c6df897b93b11b (patch)
treee7a1ecc8998edf159eae5d927767c119d93783f1 /jstests
parent5e64d72ebb0b8cd8b7d13a0b7ad590c973161468 (diff)
downloadmongo-30725e9c2316bf28a79d15d681c6df897b93b11b.tar.gz
SERVER-57256: Add deprecation message for count command and direct reader to docs
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthrough/deprecated_count.js37
1 files changed, 37 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);
+})();