summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@mongodb.com>2019-10-07 20:11:46 +0000
committerevergreen <evergreen@mongodb.com>2019-10-07 20:11:46 +0000
commit8784ad77c5a1e2327c5c0b9f50343e0186f6bfab (patch)
tree32180abaaab0be6d8eda0c35d74aba6d1a213e54
parent7538504cb584720c2cbbc6d44ea62d0743b41fcf (diff)
downloadmongo-8784ad77c5a1e2327c5c0b9f50343e0186f6bfab.tar.gz
SERVER-43273 Add UUID support to count and getIndexSpecs in DBClient
-rw-r--r--src/mongo/client/dbclient_base.cpp41
-rw-r--r--src/mongo/client/dbclient_base.h12
-rw-r--r--src/mongo/db/cloner.cpp5
-rw-r--r--src/mongo/db/commands/mr.cpp2
-rw-r--r--src/mongo/db/dbdirectclient.cpp8
-rw-r--r--src/mongo/db/dbdirectclient.h2
-rw-r--r--src/mongo/db/ops/write_ops_document_stream_integration_test.cpp4
-rw-r--r--src/mongo/db/pipeline/document_source_out.cpp2
-rw-r--r--src/mongo/db/pipeline/process_interface_standalone.cpp2
-rw-r--r--src/mongo/db/s/collection_range_deleter_test.cpp50
-rw-r--r--src/mongo/db/s/shard_metadata_util_test.cpp2
-rw-r--r--src/mongo/db/s/shardsvr_shard_collection.cpp2
-rw-r--r--src/mongo/db/s/split_vector_test.cpp6
-rw-r--r--src/mongo/db/sessions_collection_rs.cpp2
-rw-r--r--src/mongo/db/sessions_collection_standalone.cpp2
-rw-r--r--src/mongo/dbtests/clienttests.cpp20
-rw-r--r--src/mongo/dbtests/commandtests.cpp4
-rw-r--r--src/mongo/dbtests/counttests.cpp8
-rw-r--r--src/mongo/dbtests/directclienttests.cpp4
-rw-r--r--src/mongo/dbtests/indexupdatetests.cpp10
-rw-r--r--src/mongo/dbtests/logical_sessions_tests.cpp2
-rw-r--r--src/mongo/dbtests/query_stage_update.cpp2
-rw-r--r--src/mongo/dbtests/querytests.cpp99
-rw-r--r--src/mongo/dbtests/repltests.cpp4
-rw-r--r--src/mongo/executor/task_executor_cursor_integration_test.cpp3
-rw-r--r--src/mongo/rpc/op_msg_integration_test.cpp8
-rw-r--r--src/mongo/s/commands/cluster_map_reduce.cpp2
27 files changed, 200 insertions, 108 deletions
diff --git a/src/mongo/client/dbclient_base.cpp b/src/mongo/client/dbclient_base.cpp
index 3bc0f1366f6..b91e5d0f32c 100644
--- a/src/mongo/client/dbclient_base.cpp
+++ b/src/mongo/client/dbclient_base.cpp
@@ -320,19 +320,24 @@ bool DBClientBase::runPseudoCommand(StringData db,
}
unsigned long long DBClientBase::count(
- const string& myns, const BSONObj& query, int options, int limit, int skip) {
- BSONObj cmd = _countCmd(myns, query, options, limit, skip);
+ const NamespaceStringOrUUID nsOrUuid, const BSONObj& query, int options, int limit, int skip) {
+ auto dbName = (nsOrUuid.uuid() ? nsOrUuid.dbname() : (*nsOrUuid.nss()).db().toString());
+ BSONObj cmd = _countCmd(nsOrUuid, query, options, limit, skip);
BSONObj res;
- if (!runCommand(nsToDatabase(myns), cmd, res, options))
+ if (!runCommand(dbName, cmd, res, options))
uasserted(11010, string("count fails:") + res.toString());
return res["n"].numberLong();
}
BSONObj DBClientBase::_countCmd(
- const string& myns, const BSONObj& query, int options, int limit, int skip) {
- NamespaceString ns(myns);
+ const NamespaceStringOrUUID nsOrUuid, const BSONObj& query, int options, int limit, int skip) {
BSONObjBuilder b;
- b.append("count", ns.coll());
+ if (nsOrUuid.uuid()) {
+ const auto uuid = *nsOrUuid.uuid();
+ uuid.appendToBuilder(&b, "count");
+ } else {
+ b.append("count", (*nsOrUuid.nss()).coll());
+ }
b.append("query", query);
if (limit)
b.append("limit", limit);
@@ -785,13 +790,24 @@ void DBClientBase::killCursor(const NamespaceString& ns, long long cursorId) {
OpMsgRequest::fromDBAndBody(ns.db(), KillCursorsRequest(ns, {cursorId}).toBSON()));
}
-list<BSONObj> DBClientBase::getIndexSpecs(const string& ns, int options) {
+list<BSONObj> DBClientBase::getIndexSpecs(const NamespaceStringOrUUID& nsOrUuid, int options) {
list<BSONObj> specs;
- BSONObj cmd = BSON("listIndexes" << nsToCollectionSubstring(ns) << "cursor" << BSONObj());
+ BSONObjBuilder bob;
+ if (nsOrUuid.nss()) {
+ bob.append("listIndexes", (*nsOrUuid.nss()).coll());
+ bob.append("cursor", BSONObj());
+ } else {
+ const auto uuid = (*nsOrUuid.uuid());
+ uuid.appendToBuilder(&bob, "listIndexes");
+ bob.append("cursor", BSONObj());
+ }
+
+ BSONObj cmd = bob.obj();
+ auto dbName = (nsOrUuid.uuid() ? nsOrUuid.dbname() : (*nsOrUuid.nss()).db().toString());
BSONObj res;
- if (runCommand(nsToDatabase(ns), cmd, res, options)) {
+ if (runCommand(dbName, cmd, res, options)) {
BSONObj cursorObj = res["cursor"].Obj();
BSONObjIterator i(cursorObj["firstBatch"].Obj());
while (i.more()) {
@@ -801,8 +817,11 @@ list<BSONObj> DBClientBase::getIndexSpecs(const string& ns, int options) {
const long long id = cursorObj["id"].Long();
if (id != 0) {
- invariant(ns == cursorObj["ns"].String());
- unique_ptr<DBClientCursor> cursor = getMore(ns, id, 0, 0);
+ const auto cursorNs = cursorObj["ns"].String();
+ if (nsOrUuid.nss()) {
+ invariant((*nsOrUuid.nss()).toString() == cursorNs);
+ }
+ unique_ptr<DBClientCursor> cursor = getMore(cursorNs, id, 0, 0);
while (cursor->more()) {
specs.push_back(cursor->nextSafe().getOwned());
}
diff --git a/src/mongo/client/dbclient_base.h b/src/mongo/client/dbclient_base.h
index d4d5bc315e0..194210f8a24 100644
--- a/src/mongo/client/dbclient_base.h
+++ b/src/mongo/client/dbclient_base.h
@@ -351,7 +351,7 @@ public:
/** count number of objects in collection ns that match the query criteria specified
throws UserAssertion if database returns an error
*/
- virtual unsigned long long count(const std::string& ns,
+ virtual unsigned long long count(NamespaceStringOrUUID nsOrUuid,
const BSONObj& query = BSONObj(),
int options = 0,
int limit = 0,
@@ -500,7 +500,8 @@ public:
*/
virtual void createIndexes(StringData ns, const std::vector<BSONObj>& specs);
- virtual std::list<BSONObj> getIndexSpecs(const std::string& ns, int options = 0);
+ virtual std::list<BSONObj> getIndexSpecs(const NamespaceStringOrUUID& nsOrUuid,
+ int options = 0);
virtual void dropIndex(const std::string& ns, BSONObj keys);
virtual void dropIndex(const std::string& ns, const std::string& indexName);
@@ -687,8 +688,11 @@ protected:
/** if the element contains a not master error */
bool isNotMasterErrorString(const BSONElement& e);
- BSONObj _countCmd(
- const std::string& ns, const BSONObj& query, int options, int limit, int skip);
+ BSONObj _countCmd(const NamespaceStringOrUUID nsOrUuid,
+ const BSONObj& query,
+ int options,
+ int limit,
+ int skip);
/**
* Look up the options available on this client. Caches the answer from
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 514097ecc87..53822544435 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -467,7 +467,7 @@ bool Cloner::copyCollection(OperationContext* opCtx,
}
BSONObj options = optionsBob.obj();
- auto sourceIndexes = _conn->getIndexSpecs(nss.ns(), QueryOption_SlaveOk);
+ auto sourceIndexes = _conn->getIndexSpecs(nss, QueryOption_SlaveOk);
auto idIndexSpec = getIdIndexSpec(sourceIndexes);
Lock::DBLock dbWrite(opCtx, dbname, MODE_X);
@@ -752,8 +752,7 @@ Status Cloner::copyDb(OperationContext* opCtx,
Lock::TempRelease tempRelease(opCtx->lockState());
for (auto&& params : createCollectionParams) {
const NamespaceString nss(opts.fromDB, params.collectionName);
- auto indexSpecs =
- _conn->getIndexSpecs(nss.ns(), opts.slaveOk ? QueryOption_SlaveOk : 0);
+ auto indexSpecs = _conn->getIndexSpecs(nss, opts.slaveOk ? QueryOption_SlaveOk : 0);
collectionIndexSpecs[params.collectionName] = indexSpecs;
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 4a9c6adb937..b9d90555d4e 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -1218,7 +1218,7 @@ void State::finalReduce(OperationContext* opCtx, CurOp* curOp) {
BSONObj prev;
BSONList all;
- const auto count = _db.count(_config.incLong.ns(), BSONObj(), QueryOption_SlaveOk);
+ const auto count = _db.count(_config.incLong, BSONObj(), QueryOption_SlaveOk);
ProgressMeterHolder pm;
{
stdx::unique_lock<Client> lk(*opCtx->getClient());
diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp
index d5ce4367612..be41cc3c86a 100644
--- a/src/mongo/db/dbdirectclient.cpp
+++ b/src/mongo/db/dbdirectclient.cpp
@@ -173,14 +173,14 @@ unique_ptr<DBClientCursor> DBDirectClient::query(const NamespaceStringOrUUID& ns
}
unsigned long long DBDirectClient::count(
- const string& ns, const BSONObj& query, int options, int limit, int skip) {
+ const NamespaceStringOrUUID nsOrUuid, const BSONObj& query, int options, int limit, int skip) {
DirectClientScope directClientScope(_opCtx);
- BSONObj cmdObj = _countCmd(ns, query, options, limit, skip);
+ BSONObj cmdObj = _countCmd(nsOrUuid, query, options, limit, skip);
- NamespaceString nsString(ns);
+ auto dbName = (nsOrUuid.uuid() ? nsOrUuid.dbname() : (*nsOrUuid.nss()).db().toString());
auto result = CommandHelpers::runCommandDirectly(
- _opCtx, OpMsgRequest::fromDBAndBody(nsString.db(), std::move(cmdObj)));
+ _opCtx, OpMsgRequest::fromDBAndBody(dbName, std::move(cmdObj)));
uassertStatusOK(getStatusFromCommandResult(result));
return static_cast<unsigned long long>(result["n"].numberLong());
diff --git a/src/mongo/db/dbdirectclient.h b/src/mongo/db/dbdirectclient.h
index c700baf3d8f..544d1801bcf 100644
--- a/src/mongo/db/dbdirectclient.h
+++ b/src/mongo/db/dbdirectclient.h
@@ -81,7 +81,7 @@ public:
virtual void say(Message& toSend, bool isRetry = false, std::string* actualServer = nullptr);
- virtual unsigned long long count(const std::string& ns,
+ virtual unsigned long long count(const NamespaceStringOrUUID nsOrUuid,
const BSONObj& query = BSONObj(),
int options = 0,
int limit = 0,
diff --git a/src/mongo/db/ops/write_ops_document_stream_integration_test.cpp b/src/mongo/db/ops/write_ops_document_stream_integration_test.cpp
index 529cdb20532..4cd0a41a7d7 100644
--- a/src/mongo/db/ops/write_ops_document_stream_integration_test.cpp
+++ b/src/mongo/db/ops/write_ops_document_stream_integration_test.cpp
@@ -46,7 +46,7 @@ TEST(WriteOpsDocSeq, InsertDocStreamWorks) {
NamespaceString ns("test", "doc_seq");
conn->dropCollection(ns.ns());
- ASSERT_EQ(conn->count(ns.ns()), 0u);
+ ASSERT_EQ(conn->count(ns), 0u);
OpMsgRequest request;
request.body = BSON("insert" << ns.coll() << "$db" << ns.db());
@@ -64,7 +64,7 @@ TEST(WriteOpsDocSeq, InsertDocStreamWorks) {
auto body = reply->getCommandReply();
ASSERT_OK(getStatusFromCommandResult(body));
ASSERT_EQ(body["n"].Int(), 5);
- ASSERT_EQ(conn->count(ns.ns()), 5u);
+ ASSERT_EQ(conn->count(ns), 5u);
}
} // namespace mongo
diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp
index f4b7127a83d..5a94a997515 100644
--- a/src/mongo/db/pipeline/document_source_out.cpp
+++ b/src/mongo/db/pipeline/document_source_out.cpp
@@ -112,7 +112,7 @@ void DocumentSourceOut::initialize() {
// Save the original collection options and index specs so we can check they didn't change
// during computation.
_originalOutOptions = pExpCtx->mongoProcessInterface->getCollectionOptions(outputNs);
- _originalIndexes = conn->getIndexSpecs(outputNs.ns());
+ _originalIndexes = conn->getIndexSpecs(outputNs);
// Check if it's capped to make sure we have a chance of succeeding before we do all the work.
// If the collection becomes capped during processing, the collection options will have changed,
diff --git a/src/mongo/db/pipeline/process_interface_standalone.cpp b/src/mongo/db/pipeline/process_interface_standalone.cpp
index b2cf5722c7b..5f7955a2f49 100644
--- a/src/mongo/db/pipeline/process_interface_standalone.cpp
+++ b/src/mongo/db/pipeline/process_interface_standalone.cpp
@@ -359,7 +359,7 @@ void MongoInterfaceStandalone::renameIfOptionsAndIndexesHaveNotChanged(
SimpleBSONObjComparator::kInstance.evaluate(originalCollectionOptions ==
getCollectionOptions(targetNs)));
- auto currentIndexes = _client.getIndexSpecs(targetNs.ns());
+ auto currentIndexes = _client.getIndexSpecs(targetNs);
uassert(ErrorCodes::CommandFailed,
str::stream() << "indexes of target collection " << targetNs.ns()
<< " changed during processing.",
diff --git a/src/mongo/db/s/collection_range_deleter_test.cpp b/src/mongo/db/s/collection_range_deleter_test.cpp
index f6f6beb43c6..a14e660bc9a 100644
--- a/src/mongo/db/s/collection_range_deleter_test.cpp
+++ b/src/mongo/db/s/collection_range_deleter_test.cpp
@@ -178,7 +178,7 @@ TEST_F(CollectionRangeDeleterTest, OneDocumentInOneRangeToClean) {
ASSERT_TRUE(dbclient.findOne(kNss.toString(), QUERY(kShardKey << 5)).isEmpty());
ASSERT_FALSE(next(rangeDeleter, 1));
- ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer.ns(), BSON(kShardKey << "startRangeDeletion")));
+ ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer, BSON(kShardKey << "startRangeDeletion")));
}
// Tests the case that there are multiple documents within a range to clean.
@@ -188,7 +188,7 @@ TEST_F(CollectionRangeDeleterTest, MultipleDocumentsInOneRangeToClean) {
dbclient.insert(kNss.toString(), BSON(kShardKey << 1));
dbclient.insert(kNss.toString(), BSON(kShardKey << 2));
dbclient.insert(kNss.toString(), BSON(kShardKey << 3));
- ASSERT_EQUALS(3ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(3ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
std::list<Deletion> ranges;
auto deletion = Deletion{ChunkRange(BSON(kShardKey << 0), BSON(kShardKey << 10)), Date_t{}};
@@ -198,9 +198,9 @@ TEST_F(CollectionRangeDeleterTest, MultipleDocumentsInOneRangeToClean) {
ASSERT_TRUE(next(rangeDeleter, 100));
ASSERT_TRUE(next(rangeDeleter, 100));
- ASSERT_EQUALS(0ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(0ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
ASSERT_FALSE(next(rangeDeleter, 100));
- ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer.ns(), BSON(kShardKey << "startRangeDeletion")));
+ ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer, BSON(kShardKey << "startRangeDeletion")));
}
// Tests the case that there are multiple documents within a range to clean, and the range deleter
@@ -211,7 +211,7 @@ TEST_F(CollectionRangeDeleterTest, MultipleCleanupNextRangeCalls) {
dbclient.insert(kNss.toString(), BSON(kShardKey << 1));
dbclient.insert(kNss.toString(), BSON(kShardKey << 2));
dbclient.insert(kNss.toString(), BSON(kShardKey << 3));
- ASSERT_EQUALS(3ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(3ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
std::list<Deletion> ranges;
auto deletion = Deletion{ChunkRange(BSON(kShardKey << 0), BSON(kShardKey << 10)), Date_t{}};
@@ -220,16 +220,16 @@ TEST_F(CollectionRangeDeleterTest, MultipleCleanupNextRangeCalls) {
ASSERT(when && *when == Date_t{});
ASSERT_TRUE(next(rangeDeleter, 1));
- ASSERT_EQUALS(2ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(2ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
ASSERT_TRUE(next(rangeDeleter, 1));
- ASSERT_EQUALS(1ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(1ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
ASSERT_TRUE(next(rangeDeleter, 1));
ASSERT_TRUE(next(rangeDeleter, 1));
- ASSERT_EQUALS(0ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(0ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
ASSERT_FALSE(next(rangeDeleter, 1));
- ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer.ns(), BSON(kShardKey << "startRangeDeletion")));
+ ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer, BSON(kShardKey << "startRangeDeletion")));
}
// Tests the case that there are two ranges to clean, each containing multiple documents.
@@ -242,7 +242,7 @@ TEST_F(CollectionRangeDeleterTest, MultipleDocumentsInMultipleRangesToClean) {
dbclient.insert(kNss.toString(), BSON(kShardKey << 4));
dbclient.insert(kNss.toString(), BSON(kShardKey << 5));
dbclient.insert(kNss.toString(), BSON(kShardKey << 6));
- ASSERT_EQUALS(6ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 10)));
+ ASSERT_EQUALS(6ULL, dbclient.count(kNss, BSON(kShardKey << LT << 10)));
std::list<Deletion> ranges;
auto later = Date_t::now();
@@ -284,20 +284,20 @@ TEST_F(CollectionRangeDeleterTest, MultipleDocumentsInMultipleRangesToClean) {
ASSERT_FALSE(notifn1 != *optNotifn1);
// no op log entry yet
- ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer.ns(), BSON(kShardKey << "startRangeDeletion")));
+ ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer, BSON(kShardKey << "startRangeDeletion")));
- ASSERT_EQUALS(6ULL, dbclient.count(kNss.ns(), BSON(kShardKey << LT << 7)));
+ ASSERT_EQUALS(6ULL, dbclient.count(kNss, BSON(kShardKey << LT << 7)));
// catch range3, [3..4) only
auto next1 = next(rangeDeleter, 100);
ASSERT_TRUE(next1);
// no op log entry for immediate deletions
- ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer.ns(), BSON(kShardKey << "startRangeDeletion")));
+ ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer, BSON(kShardKey << "startRangeDeletion")));
// 3 gone
- ASSERT_EQUALS(5ULL, dbclient.count(kNss.ns(), BSON(kShardKey << LT << 7)));
- ASSERT_EQUALS(2ULL, dbclient.count(kNss.ns(), BSON(kShardKey << LT << 4)));
+ ASSERT_EQUALS(5ULL, dbclient.count(kNss, BSON(kShardKey << LT << 7)));
+ ASSERT_EQUALS(2ULL, dbclient.count(kNss, BSON(kShardKey << LT << 4)));
ASSERT_FALSE(notifn1.ready()); // no trigger yet
ASSERT_FALSE(notifn2.ready()); // no trigger yet
@@ -308,11 +308,11 @@ TEST_F(CollectionRangeDeleterTest, MultipleDocumentsInMultipleRangesToClean) {
ASSERT_TRUE(next2);
// still no op log entry, because not delayed
- ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer.ns(), BSON(kShardKey << "startRangeDeletion")));
+ ASSERT_EQUALS(0ULL, dbclient.count(kAdminSysVer, BSON(kShardKey << "startRangeDeletion")));
// deleted 1, 5 left
- ASSERT_EQUALS(2ULL, dbclient.count(kNss.ns(), BSON(kShardKey << LT << 4)));
- ASSERT_EQUALS(5ULL, dbclient.count(kNss.ns(), BSON(kShardKey << LT << 10)));
+ ASSERT_EQUALS(2ULL, dbclient.count(kNss, BSON(kShardKey << LT << 4)));
+ ASSERT_EQUALS(5ULL, dbclient.count(kNss, BSON(kShardKey << LT << 10)));
ASSERT_FALSE(notifn1.ready()); // no trigger yet
ASSERT_FALSE(notifn2.ready()); // no trigger yet
@@ -328,9 +328,9 @@ TEST_F(CollectionRangeDeleterTest, MultipleDocumentsInMultipleRangesToClean) {
ASSERT_FALSE(notifn2.ready()); // no trigger yet
// deleted 3, 3 left
- ASSERT_EQUALS(3ULL, dbclient.count(kNss.ns(), BSON(kShardKey << LT << 10)));
+ ASSERT_EQUALS(3ULL, dbclient.count(kNss, BSON(kShardKey << LT << 10)));
- ASSERT_EQUALS(1ULL, dbclient.count(kAdminSysVer.ns(), BSON(kShardKey << "startRangeDeletion")));
+ ASSERT_EQUALS(1ULL, dbclient.count(kAdminSysVer, BSON(kShardKey << "startRangeDeletion")));
// clang-format off
ASSERT_BSONOBJ_EQ(
BSON("_id" << "startRangeDeletion" << "ns" << kNss.ns()
@@ -355,7 +355,7 @@ TEST_F(CollectionRangeDeleterTest, MultipleDocumentsInMultipleRangesToClean) {
// clang-format on
// still 3 left
- ASSERT_EQUALS(3ULL, dbclient.count(kNss.ns(), BSON(kShardKey << LT << 10)));
+ ASSERT_EQUALS(3ULL, dbclient.count(kNss, BSON(kShardKey << LT << 10)));
// delete the remaining documents
auto next5 = next(rangeDeleter, 100);
@@ -372,7 +372,7 @@ TEST_F(CollectionRangeDeleterTest, MultipleDocumentsInMultipleRangesToClean) {
// clang-format on
// all docs gone
- ASSERT_EQUALS(0ULL, dbclient.count(kNss.ns(), BSON(kShardKey << LT << 10)));
+ ASSERT_EQUALS(0ULL, dbclient.count(kNss, BSON(kShardKey << LT << 10)));
// discover there are no more, pop range 2
auto next6 = next(rangeDeleter, 100);
@@ -393,7 +393,7 @@ TEST_F(CollectionRangeDeleterTest, RetryOnWriteConflictException) {
dbclient.insert(kNss.toString(), BSON(kShardKey << 1));
dbclient.insert(kNss.toString(), BSON(kShardKey << 2));
dbclient.insert(kNss.toString(), BSON(kShardKey << 3));
- ASSERT_EQUALS(3ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(3ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
std::list<Deletion> ranges;
auto deletion = Deletion{ChunkRange(BSON(kShardKey << 0), BSON(kShardKey << 10)), Date_t{}};
@@ -405,13 +405,13 @@ TEST_F(CollectionRangeDeleterTest, RetryOnWriteConflictException) {
rangeDeleter.setDoDeletionShouldThrowWriteConflictForTest(true);
ASSERT_TRUE(next(rangeDeleter, 1));
- ASSERT_EQUALS(3ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(3ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
// TODO SERVER-41606: Remove this function when we refactor CollectionRangeDeleter.
rangeDeleter.setDoDeletionShouldThrowWriteConflictForTest(false);
ASSERT_TRUE(next(rangeDeleter, 1));
- ASSERT_EQUALS(2ULL, dbclient.count(kNss.toString(), BSON(kShardKey << LT << 5)));
+ ASSERT_EQUALS(2ULL, dbclient.count(kNss, BSON(kShardKey << LT << 5)));
}
} // namespace
diff --git a/src/mongo/db/s/shard_metadata_util_test.cpp b/src/mongo/db/s/shard_metadata_util_test.cpp
index 110cecee0bb..771dbab13ec 100644
--- a/src/mongo/db/s/shard_metadata_util_test.cpp
+++ b/src/mongo/db/s/shard_metadata_util_test.cpp
@@ -129,7 +129,7 @@ struct ShardMetadataUtilTest : public ShardServerTestFixture {
void checkCollectionIsEmpty(const NamespaceString& nss) {
try {
DBDirectClient client(operationContext());
- ASSERT_EQUALS(client.count(nss.ns()), 0ULL);
+ ASSERT_EQUALS(client.count(nss), 0ULL);
} catch (const DBException&) {
ASSERT(false);
}
diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp
index af579daa7cd..c3e21103c37 100644
--- a/src/mongo/db/s/shardsvr_shard_collection.cpp
+++ b/src/mongo/db/s/shardsvr_shard_collection.cpp
@@ -219,7 +219,7 @@ void createCollectionOrValidateExisting(OperationContext* opCtx,
// 5. If the collection is empty, and it's still possible to create an index
// on the proposed key, we go ahead and do so.
DBDirectClient localClient(opCtx);
- std::list<BSONObj> indexes = localClient.getIndexSpecs(nss.ns());
+ std::list<BSONObj> indexes = localClient.getIndexSpecs(nss);
// 1. Verify consistency with existing unique indexes
for (const auto& idx : indexes) {
diff --git a/src/mongo/db/s/split_vector_test.cpp b/src/mongo/db/s/split_vector_test.cpp
index 0db74b87b66..22e226ff4ce 100644
--- a/src/mongo/db/s/split_vector_test.cpp
+++ b/src/mongo/db/s/split_vector_test.cpp
@@ -59,7 +59,7 @@ public:
BSONObj obj = builder.obj();
dbclient.insert(kNss.toString(), obj);
}
- ASSERT_EQUALS(100ULL, dbclient.count(kNss.toString()));
+ ASSERT_EQUALS(100ULL, dbclient.count(kNss));
}
const long long& getDocSizeBytes() {
@@ -320,7 +320,7 @@ public:
for (int i = 0; i < 1000; i++) {
dbclient.insert(kJumboNss.toString(), obj);
}
- ASSERT_EQUALS(1000ULL, dbclient.count(kJumboNss.toString()));
+ ASSERT_EQUALS(1000ULL, dbclient.count(kJumboNss));
}
const long long& getDocSizeBytes() {
@@ -377,7 +377,7 @@ public:
BSONObj obj = builder.obj();
dbclient.insert(kMaxResponseNss.toString(), obj);
}
- ASSERT_EQUALS(numDocs, (int)dbclient.count(kMaxResponseNss.toString()));
+ ASSERT_EQUALS(numDocs, (int)dbclient.count(kMaxResponseNss));
}
std::string createUniqueHalfMegabyteString(int uniqueInt) {
diff --git a/src/mongo/db/sessions_collection_rs.cpp b/src/mongo/db/sessions_collection_rs.cpp
index c6aaa9d0a94..316b95b53de 100644
--- a/src/mongo/db/sessions_collection_rs.cpp
+++ b/src/mongo/db/sessions_collection_rs.cpp
@@ -154,7 +154,7 @@ Status SessionsCollectionRS::setupSessionsCollection(OperationContext* opCtx) {
Status SessionsCollectionRS::checkSessionsCollectionExists(OperationContext* opCtx) {
DBDirectClient client(opCtx);
- auto indexes = client.getIndexSpecs(NamespaceString::kLogicalSessionsNamespace.toString());
+ auto indexes = client.getIndexSpecs(NamespaceString::kLogicalSessionsNamespace);
if (indexes.size() == 0u) {
return Status{ErrorCodes::NamespaceNotFound, "config.system.sessions does not exist"};
diff --git a/src/mongo/db/sessions_collection_standalone.cpp b/src/mongo/db/sessions_collection_standalone.cpp
index 764cf9ccaea..2b1f815decc 100644
--- a/src/mongo/db/sessions_collection_standalone.cpp
+++ b/src/mongo/db/sessions_collection_standalone.cpp
@@ -71,7 +71,7 @@ Status SessionsCollectionStandalone::setupSessionsCollection(OperationContext* o
Status SessionsCollectionStandalone::checkSessionsCollectionExists(OperationContext* opCtx) {
DBDirectClient client(opCtx);
- auto indexes = client.getIndexSpecs(NamespaceString::kLogicalSessionsNamespace.toString());
+ auto indexes = client.getIndexSpecs(NamespaceString::kLogicalSessionsNamespace);
if (indexes.size() == 0u) {
return Status{ErrorCodes::NamespaceNotFound, "config.system.sessions does not exist"};
diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp
index 77d690847cd..a18f4c259b7 100644
--- a/src/mongo/dbtests/clienttests.cpp
+++ b/src/mongo/dbtests/clienttests.cpp
@@ -62,6 +62,10 @@ public:
db.dropCollection(_ns);
}
+ const NamespaceString nss() {
+ return NamespaceString(_ns);
+ }
+
const char* ns() {
return _ns.c_str();
}
@@ -79,19 +83,19 @@ public:
DBDirectClient db(&opCtx);
db.insert(ns(), BSON("x" << 2));
- ASSERT_EQUALS(1u, db.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(1u, db.getIndexSpecs(nss()).size());
ASSERT_OK(dbtests::createIndex(&opCtx, ns(), BSON("x" << 1)));
- ASSERT_EQUALS(2u, db.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(2u, db.getIndexSpecs(nss()).size());
db.dropIndex(ns(), BSON("x" << 1));
- ASSERT_EQUALS(1u, db.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(1u, db.getIndexSpecs(nss()).size());
ASSERT_OK(dbtests::createIndex(&opCtx, ns(), BSON("x" << 1)));
- ASSERT_EQUALS(2u, db.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(2u, db.getIndexSpecs(nss()).size());
db.dropIndexes(ns());
- ASSERT_EQUALS(1u, db.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(1u, db.getIndexSpecs(nss()).size());
}
};
@@ -118,18 +122,18 @@ public:
ASSERT_EQUALS(1, indexCatalog->numIndexesReady(&opCtx));
// _id index
- ASSERT_EQUALS(1U, db.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(1U, db.getIndexSpecs(nss()).size());
ASSERT_EQUALS(ErrorCodes::DuplicateKey,
dbtests::createIndex(&opCtx, ns(), BSON("y" << 1), true));
ASSERT_EQUALS(1, indexCatalog->numIndexesReady(&opCtx));
- ASSERT_EQUALS(1U, db.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(1U, db.getIndexSpecs(nss()).size());
ASSERT_OK(dbtests::createIndex(&opCtx, ns(), BSON("x" << 1), true));
ASSERT_EQUALS(2, indexCatalog->numIndexesReady(&opCtx));
- ASSERT_EQUALS(2U, db.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(2U, db.getIndexSpecs(nss()).size());
}
};
diff --git a/src/mongo/dbtests/commandtests.cpp b/src/mongo/dbtests/commandtests.cpp
index 2a464621bcd..efce5cb65e3 100644
--- a/src/mongo/dbtests/commandtests.cpp
+++ b/src/mongo/dbtests/commandtests.cpp
@@ -50,7 +50,7 @@ TEST(CommandTests, InputDocumentSequeceWorksEndToEnd) {
NamespaceString nss("test", "doc_seq");
DBDirectClient db(opCtx);
db.dropCollection(nss.ns());
- ASSERT_EQ(db.count(nss.ns()), 0u);
+ ASSERT_EQ(db.count(nss), 0u);
OpMsgRequest request;
request.body = BSON("insert" << nss.coll() << "$db" << nss.db());
@@ -66,7 +66,7 @@ TEST(CommandTests, InputDocumentSequeceWorksEndToEnd) {
const auto reply = db.runCommand(std::move(request));
ASSERT_EQ(int(reply->getProtocol()), int(rpc::Protocol::kOpMsg));
ASSERT_BSONOBJ_EQ(reply->getCommandReply(), BSON("n" << 5 << "ok" << 1.0));
- ASSERT_EQ(db.count(nss.ns()), 5u);
+ ASSERT_EQ(db.count(nss), 5u);
}
using std::string;
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index 86f3ac51b71..9329f88245f 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -123,7 +123,7 @@ public:
void run() {
insert("{\"a\":\"b\"}");
insert("{\"c\":\"d\"}");
- ASSERT_EQUALS(2ULL, _client.count(ns(), fromjson("{}")));
+ ASSERT_EQUALS(2ULL, _client.count(nss(), fromjson("{}")));
}
};
@@ -133,7 +133,7 @@ public:
insert("{\"a\":\"b\"}");
insert("{\"a\":\"b\",\"x\":\"y\"}");
insert("{\"a\":\"c\"}");
- ASSERT_EQUALS(2ULL, _client.count(ns(), fromjson("{\"a\":\"b\"}")));
+ ASSERT_EQUALS(2ULL, _client.count(nss(), fromjson("{\"a\":\"b\"}")));
}
};
@@ -143,7 +143,7 @@ public:
insert("{\"a\":\"b\"}");
insert("{\"a\":\"c\"}");
insert("{\"d\":\"e\"}");
- ASSERT_EQUALS(1ULL, _client.count(ns(), fromjson("{\"a\":\"b\"}")));
+ ASSERT_EQUALS(1ULL, _client.count(nss(), fromjson("{\"a\":\"b\"}")));
}
};
@@ -153,7 +153,7 @@ public:
insert("{\"a\":\"c\"}");
insert("{\"a\":\"b\"}");
insert("{\"a\":\"d\"}");
- ASSERT_EQUALS(1ULL, _client.count(ns(), fromjson("{\"a\":/^b/}")));
+ ASSERT_EQUALS(1ULL, _client.count(nss(), fromjson("{\"a\":/^b/}")));
}
};
diff --git a/src/mongo/dbtests/directclienttests.cpp b/src/mongo/dbtests/directclienttests.cpp
index c1b80628851..5b120ee484e 100644
--- a/src/mongo/dbtests/directclienttests.cpp
+++ b/src/mongo/dbtests/directclienttests.cpp
@@ -105,12 +105,12 @@ public:
client.dropCollection(ns);
client.insert(ns, objs);
ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(), 11000);
- ASSERT_EQUALS((int)client.count(ns), 1);
+ ASSERT_EQUALS((int)client.count(NamespaceString(ns)), 1);
client.dropCollection(ns);
client.insert(ns, objs, InsertOption_ContinueOnError);
ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(), 11000);
- ASSERT_EQUALS((int)client.count(ns), 2);
+ ASSERT_EQUALS((int)client.count(NamespaceString(ns)), 2);
}
};
diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp
index 6ceebc55c1b..244b2088119 100644
--- a/src/mongo/dbtests/indexupdatetests.cpp
+++ b/src/mongo/dbtests/indexupdatetests.cpp
@@ -532,7 +532,7 @@ public:
client.insert(_ns, BSON("a" << BSONSymbol("mySymbol")));
ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(),
ErrorCodes::CannotBuildIndexKeys);
- ASSERT_EQUALS(client.count(_ns), 0U);
+ ASSERT_EQUALS(client.count(_nss), 0U);
}
};
@@ -547,7 +547,7 @@ public:
client.createIndex(_ns, indexSpec);
client.insert(_ns, BSON("a" << BSONSymbol("mySymbol")));
ASSERT(client.getLastError().empty());
- ASSERT_EQUALS(client.count(_ns), 1U);
+ ASSERT_EQUALS(client.count(_nss), 1U);
}
};
@@ -564,7 +564,7 @@ public:
client.insert(_ns, BSON("a" << BSON("b" << 99 << "c" << BSONSymbol("mySymbol"))));
ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(),
ErrorCodes::CannotBuildIndexKeys);
- ASSERT_EQUALS(client.count(_ns), 0U);
+ ASSERT_EQUALS(client.count(_nss), 0U);
}
};
@@ -581,7 +581,7 @@ public:
client.insert(_ns, BSON("a" << BSON_ARRAY(99 << BSONSymbol("mySymbol"))));
ASSERT_EQUALS(client.getLastErrorDetailed()["code"].numberInt(),
ErrorCodes::CannotBuildIndexKeys);
- ASSERT_EQUALS(client.count(_ns), 0U);
+ ASSERT_EQUALS(client.count(_nss), 0U);
}
};
@@ -592,7 +592,7 @@ public:
DBDirectClient client(opCtx.get());
client.dropCollection(_ns);
client.insert(_ns, BSON("a" << BSON_ARRAY(99 << BSONSymbol("mySymbol"))));
- ASSERT_EQUALS(client.count(_ns), 1U);
+ ASSERT_EQUALS(client.count(_nss), 1U);
IndexSpec indexSpec;
indexSpec.addKey("a").addOptions(BSON("collation" << BSON("locale"
<< "fr")));
diff --git a/src/mongo/dbtests/logical_sessions_tests.cpp b/src/mongo/dbtests/logical_sessions_tests.cpp
index 13d3cb75e14..94b0123afce 100644
--- a/src/mongo/dbtests/logical_sessions_tests.cpp
+++ b/src/mongo/dbtests/logical_sessions_tests.cpp
@@ -199,7 +199,7 @@ public:
ASSERT(resRefresh.isOK());
// Ensure that the right number of timestamps were updated.
- auto n = db.count(ns(), BSON("lastUse" << now));
+ auto n = db.count(NamespaceString(ns()), BSON("lastUse" << now));
ASSERT_EQ(n, notRefreshed);
}
};
diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp
index c0dc47528e4..d83b8479033 100644
--- a/src/mongo/dbtests/query_stage_update.cpp
+++ b/src/mongo/dbtests/query_stage_update.cpp
@@ -94,7 +94,7 @@ public:
}
size_t count(const BSONObj& query) {
- return _client.count(nss.ns(), query, 0, 0, 0);
+ return _client.count(nss, query, 0, 0, 0);
}
unique_ptr<CanonicalQuery> canonicalize(const BSONObj& query) {
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index ba0a9eac64d..24bbc5be371 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -809,7 +809,8 @@ public:
private:
void count(unsigned long long c) {
- ASSERT_EQUALS(c, _client.count("unittests.querytests.BasicCount", BSON("a" << 4)));
+ ASSERT_EQUALS(
+ c, _client.count(NamespaceString("unittests.querytests.BasicCount"), BSON("a" << 4)));
}
};
@@ -904,11 +905,14 @@ public:
static const char* ns() {
return "unittests.querytests.AutoResetIndexCache";
}
+ static const NamespaceString nss() {
+ return NamespaceString(ns());
+ }
void index() {
- ASSERT_EQUALS(2u, _client.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(2u, _client.getIndexSpecs(nss()).size());
}
void noIndex() {
- ASSERT_EQUALS(0u, _client.getIndexSpecs(ns()).size());
+ ASSERT_EQUALS(0u, _client.getIndexSpecs(nss()).size());
}
void checkIndex() {
ASSERT_OK(dbtests::createIndex(&_opCtx, ns(), BSON("a" << 1)));
@@ -934,15 +938,16 @@ public:
}
void run() {
const char* ns = "unittests.querytests.UniqueIndex";
+ const NamespaceString nss = NamespaceString(ns);
ASSERT_OK(dbtests::createIndex(&_opCtx, ns, BSON("a" << 1), true));
_client.insert(ns, BSON("a" << 4 << "b" << 2));
_client.insert(ns, BSON("a" << 4 << "b" << 3));
- ASSERT_EQUALS(1U, _client.count(ns, BSONObj()));
+ ASSERT_EQUALS(1U, _client.count(nss, BSONObj()));
_client.dropCollection(ns);
ASSERT_OK(dbtests::createIndex(&_opCtx, ns, BSON("b" << 1), true));
_client.insert(ns, BSON("a" << 4 << "b" << 2));
_client.insert(ns, BSON("a" << 4 << "b" << 3));
- ASSERT_EQUALS(2U, _client.count(ns, BSONObj()));
+ ASSERT_EQUALS(2U, _client.count(nss, BSONObj()));
}
};
@@ -1129,7 +1134,7 @@ BSONObj MinMax::empty_;
class MatchCodeCodeWScope : public ClientBase {
public:
- MatchCodeCodeWScope() : _ns("unittests.querytests.MatchCodeCodeWScope") {}
+ MatchCodeCodeWScope() : _ns("unittests.querytests.MatchCodeCodeWScope"), _nss(_ns) {}
~MatchCodeCodeWScope() {
_client.dropCollection("unittests.querytests.MatchCodeCodeWScope");
}
@@ -1146,11 +1151,11 @@ private:
_client.insert(_ns, code());
_client.insert(_ns, codeWScope());
- ASSERT_EQUALS(1U, _client.count(_ns, code()));
- ASSERT_EQUALS(1U, _client.count(_ns, codeWScope()));
+ ASSERT_EQUALS(1U, _client.count(_nss, code()));
+ ASSERT_EQUALS(1U, _client.count(_nss, codeWScope()));
- ASSERT_EQUALS(1U, _client.count(_ns, BSON("a" << BSON("$type" << (int)Code))));
- ASSERT_EQUALS(1U, _client.count(_ns, BSON("a" << BSON("$type" << (int)CodeWScope))));
+ ASSERT_EQUALS(1U, _client.count(_nss, BSON("a" << BSON("$type" << (int)Code))));
+ ASSERT_EQUALS(1U, _client.count(_nss, BSON("a" << BSON("$type" << (int)CodeWScope))));
}
BSONObj code() const {
BSONObjBuilder codeBuilder;
@@ -1163,11 +1168,12 @@ private:
return codeWScopeBuilder.obj();
}
const char* _ns;
+ const NamespaceString _nss;
};
class MatchDBRefType : public ClientBase {
public:
- MatchDBRefType() : _ns("unittests.querytests.MatchDBRefType") {}
+ MatchDBRefType() : _ns("unittests.querytests.MatchDBRefType"), _nss(_ns) {}
~MatchDBRefType() {
_client.dropCollection("unittests.querytests.MatchDBRefType");
}
@@ -1181,8 +1187,8 @@ private:
void checkMatch() {
_client.remove(_ns, BSONObj());
_client.insert(_ns, dbref());
- ASSERT_EQUALS(1U, _client.count(_ns, dbref()));
- ASSERT_EQUALS(1U, _client.count(_ns, BSON("a" << BSON("$type" << (int)DBRef))));
+ ASSERT_EQUALS(1U, _client.count(_nss, dbref()));
+ ASSERT_EQUALS(1U, _client.count(_nss, BSON("a" << BSON("$type" << (int)DBRef))));
}
BSONObj dbref() const {
BSONObjBuilder b;
@@ -1191,6 +1197,7 @@ private:
return b.obj();
}
const char* _ns;
+ const NamespaceString _nss;
};
class DirectLocking : public ClientBase {
@@ -1215,7 +1222,7 @@ public:
BSON("i"
<< "a"));
ASSERT_OK(dbtests::createIndex(&_opCtx, ns, BSON("i" << 1)));
- ASSERT_EQUALS(1U, _client.count(ns, fromjson("{i:{$in:['a']}}")));
+ ASSERT_EQUALS(1U, _client.count(NamespaceString(ns), fromjson("{i:{$in:['a']}}")));
}
};
@@ -1231,11 +1238,11 @@ public:
_client.insert(ns, fromjson("{bar:['spam']}"));
_client.insert(ns, fromjson("{bar:['spam','eggs']}"));
ASSERT_EQUALS(2U,
- _client.count(ns,
+ _client.count(NamespaceString(ns),
BSON("bar"
<< "spam")));
ASSERT_EQUALS(2U,
- _client.count(ns,
+ _client.count(NamespaceString(ns),
BSON("foo.bar"
<< "spam")));
}
@@ -1305,7 +1312,7 @@ public:
}
int count() {
- return (int)_client.count(ns());
+ return (int)_client.count(nss());
}
size_t numCursorsOpen() {
@@ -1756,6 +1763,63 @@ public:
}
};
+class CountByUUID : public CollectionBase {
+public:
+ CountByUUID() : CollectionBase("CountByUUID") {}
+
+ void run() {
+ CollectionOptions coll_opts;
+ coll_opts.uuid = UUID::gen();
+ {
+ Lock::GlobalWrite lk(&_opCtx);
+ OldClientContext context(&_opCtx, ns());
+ WriteUnitOfWork wunit(&_opCtx);
+ context.db()->createCollection(&_opCtx, nss(), coll_opts, false);
+ wunit.commit();
+ }
+ insert(ns(), BSON("a" << 1));
+
+ auto count = _client.count(NamespaceStringOrUUID("unittests", *coll_opts.uuid), BSONObj());
+ ASSERT_EQUALS(1U, count);
+
+ insert(ns(), BSON("a" << 2));
+ insert(ns(), BSON("a" << 3));
+
+ count = _client.count(NamespaceStringOrUUID("unittests", *coll_opts.uuid), BSONObj());
+ ASSERT_EQUALS(3U, count);
+ }
+};
+
+class GetIndexSpecsByUUID : public CollectionBase {
+public:
+ GetIndexSpecsByUUID() : CollectionBase("GetIndexSpecsByUUID") {}
+
+ void run() {
+ CollectionOptions coll_opts;
+ coll_opts.uuid = UUID::gen();
+ {
+ Lock::GlobalWrite lk(&_opCtx);
+ OldClientContext context(&_opCtx, ns());
+ WriteUnitOfWork wunit(&_opCtx);
+ context.db()->createCollection(&_opCtx, nss(), coll_opts, true);
+ wunit.commit();
+ }
+ insert(ns(), BSON("a" << 1));
+ insert(ns(), BSON("a" << 2));
+ insert(ns(), BSON("a" << 3));
+
+ auto specsWithIdIndexOnly =
+ _client.getIndexSpecs(NamespaceStringOrUUID(nss().db().toString(), *coll_opts.uuid));
+ ASSERT_EQUALS(1U, specsWithIdIndexOnly.size());
+
+ ASSERT_OK(dbtests::createIndex(&_opCtx, ns(), BSON("a" << 1), true));
+
+ auto specsWithBothIndexes =
+ _client.getIndexSpecs(NamespaceStringOrUUID(nss().db().toString(), *coll_opts.uuid));
+ ASSERT_EQUALS(2U, specsWithBothIndexes.size());
+ }
+};
+
class CollectionInternalBase : public CollectionBase {
public:
CollectionInternalBase(const char* nsLeaf)
@@ -1918,6 +1982,7 @@ public:
add<FindingStartStale>();
add<WhatsMyUri>();
add<QueryByUuid>();
+ add<GetIndexSpecsByUUID>();
add<Exhaust>();
add<QueryReadsAll>();
add<queryobjecttests::names1>();
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index 591eafe50e5..f68017aaefb 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -1321,13 +1321,13 @@ public:
insert(BSON("_id" << 1 << "a" << 11));
insert(BSON("_id" << 3 << "a" << 10));
_client.remove(ns(), BSON("a" << 10));
- ASSERT_EQUALS(1U, _client.count(ns(), BSONObj()));
+ ASSERT_EQUALS(1U, _client.count(nss(), BSONObj()));
insert(BSON("_id" << 0 << "a" << 11));
insert(BSON("_id" << 2 << "a" << 10));
insert(BSON("_id" << 3 << "a" << 10));
applyAllOperations();
- ASSERT_EQUALS(2U, _client.count(ns(), BSONObj()));
+ ASSERT_EQUALS(2U, _client.count(nss(), BSONObj()));
ASSERT(!one(BSON("_id" << 1)).isEmpty());
ASSERT(!one(BSON("_id" << 2)).isEmpty());
}
diff --git a/src/mongo/executor/task_executor_cursor_integration_test.cpp b/src/mongo/executor/task_executor_cursor_integration_test.cpp
index 55b75650083..f5ad9b62397 100644
--- a/src/mongo/executor/task_executor_cursor_integration_test.cpp
+++ b/src/mongo/executor/task_executor_cursor_integration_test.cpp
@@ -32,6 +32,7 @@
#include "mongo/executor/task_executor_cursor.h"
#include "mongo/client/dbclient_base.h"
+#include "mongo/db/namespace_string.h"
#include "mongo/executor/network_interface_factory.h"
#include "mongo/executor/network_interface_thread_pool.h"
#include "mongo/executor/thread_pool_task_executor.h"
@@ -84,7 +85,7 @@ TEST_F(TaskExecutorCursorFixture, Basic) {
}
dbclient->dropCollection("test.test");
dbclient->insert("test.test", docs);
- ASSERT_EQUALS(dbclient->count("test.test"), numDocs);
+ ASSERT_EQUALS(dbclient->count(NamespaceString("test.test")), numDocs);
RemoteCommandRequest rcr(unittest::getFixtureConnectionString().getServers().front(),
"test",
diff --git a/src/mongo/rpc/op_msg_integration_test.cpp b/src/mongo/rpc/op_msg_integration_test.cpp
index 5cd98239b5f..8cfbf1fa6bf 100644
--- a/src/mongo/rpc/op_msg_integration_test.cpp
+++ b/src/mongo/rpc/op_msg_integration_test.cpp
@@ -84,7 +84,7 @@ TEST(OpMsg, FireAndForgetInsertWorks) {
]
})")));
- ASSERT_EQ(conn->count("test.collection"), 1u);
+ ASSERT_EQ(conn->count(NamespaceString("test.collection")), 1u);
}
TEST(OpMsg, DocumentSequenceLargeDocumentMultiInsertWorks) {
@@ -117,7 +117,7 @@ TEST(OpMsg, DocumentSequenceLargeDocumentMultiInsertWorks) {
Message reply;
ASSERT_TRUE(conn->call(request, reply, false));
- ASSERT_EQ(conn->count("test.collection"), 3u);
+ ASSERT_EQ(conn->count(NamespaceString("test.collection")), 3u);
conn->dropCollection("test.collection");
}
@@ -153,7 +153,7 @@ TEST(OpMsg, DocumentSequenceMaxWriteBatchWorks) {
Message reply;
ASSERT_TRUE(conn->call(request, reply, false));
- ASSERT_EQ(conn->count("test.collection"), write_ops::kMaxWriteBatchSize);
+ ASSERT_EQ(conn->count(NamespaceString("test.collection")), write_ops::kMaxWriteBatchSize);
conn->dropCollection("test.collection");
}
@@ -407,7 +407,7 @@ TEST(OpMsg, ExhaustWithDBClientCursorBehavesCorrectly) {
conn->insert(nss.toString(), doc, 0);
}
- ASSERT_EQ(conn->count(nss.toString()), size_t(nDocs));
+ ASSERT_EQ(conn->count(nss), size_t(nDocs));
unittest::log() << "Finished document insertion.";
// Open an exhaust cursor.
diff --git a/src/mongo/s/commands/cluster_map_reduce.cpp b/src/mongo/s/commands/cluster_map_reduce.cpp
index 6116311f582..59b6e1680ae 100644
--- a/src/mongo/s/commands/cluster_map_reduce.cpp
+++ b/src/mongo/s/commands/cluster_map_reduce.cpp
@@ -533,7 +533,7 @@ bool runMapReduce(OperationContext* opCtx,
// collection is empty in order to decide whether we should drop and re-shard
// it.
// We don't want to do this if the collection is not empty.
- shouldDropAndShard = (conn->count(outputCollNss.ns()) == 0);
+ shouldDropAndShard = (conn->count(outputCollNss) == 0);
}
conn.done();