summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/client/dbclient_base.cpp17
-rw-r--r--src/mongo/client/dbclient_base.h12
-rw-r--r--src/mongo/client/dbclient_connection.cpp6
-rw-r--r--src/mongo/client/dbclient_connection.h6
-rw-r--r--src/mongo/client/dbclient_cursor.cpp14
-rw-r--r--src/mongo/client/dbclient_cursor.h6
-rw-r--r--src/mongo/client/dbclient_mockcursor.h2
-rw-r--r--src/mongo/client/dbclient_rs.cpp8
-rw-r--r--src/mongo/client/dbclient_rs.h2
-rw-r--r--src/mongo/client/dbclient_rs_test.cpp56
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_d.cpp2
-rw-r--r--src/mongo/db/cloner.cpp2
-rw-r--r--src/mongo/db/commands/dbcommands_d.cpp2
-rw-r--r--src/mongo/db/commands/mr.cpp4
-rw-r--r--src/mongo/db/commands/user_management_commands.cpp10
-rw-r--r--src/mongo/db/dbdirectclient.cpp4
-rw-r--r--src/mongo/db/dbdirectclient.h2
-rw-r--r--src/mongo/db/repl/oplog_interface_remote.cpp5
-rw-r--r--src/mongo/db/repl/oplogreader.cpp3
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp2
-rw-r--r--src/mongo/db/repl/roll_back_local_operations_test.cpp2
-rw-r--r--src/mongo/db/s/chunk_splitter.cpp2
-rw-r--r--src/mongo/db/s/session_catalog_migration_source.cpp2
-rw-r--r--src/mongo/db/s/shard_metadata_util.cpp6
-rw-r--r--src/mongo/db/s/shard_metadata_util_test.cpp3
-rw-r--r--src/mongo/db/session_test.cpp8
-rw-r--r--src/mongo/db/transaction_reaper.cpp2
-rw-r--r--src/mongo/dbtests/clienttests.cpp6
-rw-r--r--src/mongo/dbtests/dbhelper_tests.cpp3
-rw-r--r--src/mongo/dbtests/directclienttests.cpp2
-rw-r--r--src/mongo/dbtests/logical_sessions_tests.cpp2
-rw-r--r--src/mongo/dbtests/mock/mock_dbclient_connection.cpp22
-rw-r--r--src/mongo/dbtests/mock/mock_dbclient_connection.h4
-rw-r--r--src/mongo/dbtests/mock/mock_dbclient_cursor.cpp2
-rw-r--r--src/mongo/dbtests/mock_dbclient_conn_test.cpp55
-rw-r--r--src/mongo/dbtests/querytests.cpp184
-rw-r--r--src/mongo/dbtests/repltests.cpp9
-rw-r--r--src/mongo/dbtests/updatetests.cpp3
-rw-r--r--src/mongo/s/client/parallel.cpp6
-rw-r--r--src/mongo/s/client/rs_local_client.cpp2
-rw-r--r--src/mongo/s/client/shard_connection_test.cpp8
-rw-r--r--src/mongo/scripting/engine.cpp2
-rw-r--r--src/mongo/scripting/mozjs/mongo.cpp11
-rw-r--r--src/mongo/shell/bench.cpp4
44 files changed, 291 insertions, 224 deletions
diff --git a/src/mongo/client/dbclient_base.cpp b/src/mongo/client/dbclient_base.cpp
index 378cc0a5e37..a7faffe9bcf 100644
--- a/src/mongo/client/dbclient_base.cpp
+++ b/src/mongo/client/dbclient_base.cpp
@@ -613,7 +613,7 @@ void DBClientBase::findN(vector<BSONObj>& out,
out.reserve(nToReturn);
unique_ptr<DBClientCursor> c =
- this->query(ns, query, nToReturn, nToSkip, fieldsToReturn, queryOptions);
+ this->query(NamespaceString(ns), query, nToReturn, nToSkip, fieldsToReturn, queryOptions);
uassert(10276,
str::stream() << "DBClientBase::findN: transport error: " << getServerAddress()
@@ -682,7 +682,7 @@ std::pair<BSONObj, NamespaceString> DBClientBase::findOneByUUID(const std::strin
const uint64_t DBClientBase::INVALID_SOCK_CREATION_TIME = std::numeric_limits<uint64_t>::max();
-unique_ptr<DBClientCursor> DBClientBase::query(const string& ns,
+unique_ptr<DBClientCursor> DBClientBase::query(const NamespaceStringOrUUID& nsOrUuid,
Query query,
int nToReturn,
int nToSkip,
@@ -690,7 +690,7 @@ unique_ptr<DBClientCursor> DBClientBase::query(const string& ns,
int queryOptions,
int batchSize) {
unique_ptr<DBClientCursor> c(new DBClientCursor(
- this, ns, query.obj, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize));
+ this, nsOrUuid, query.obj, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize));
if (c->init())
return c;
return nullptr;
@@ -700,7 +700,8 @@ unique_ptr<DBClientCursor> DBClientBase::getMore(const string& ns,
long long cursorId,
int nToReturn,
int options) {
- unique_ptr<DBClientCursor> c(new DBClientCursor(this, ns, cursorId, nToReturn, options));
+ unique_ptr<DBClientCursor> c(
+ new DBClientCursor(this, NamespaceString(ns), cursorId, nToReturn, options));
if (c->init())
return c;
return nullptr;
@@ -716,25 +717,25 @@ struct DBClientFunConvertor {
};
unsigned long long DBClientBase::query(stdx::function<void(const BSONObj&)> f,
- const string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
Query query,
const BSONObj* fieldsToReturn,
int queryOptions) {
DBClientFunConvertor fun;
fun._f = f;
stdx::function<void(DBClientCursorBatchIterator&)> ptr(fun);
- return this->query(ptr, ns, query, fieldsToReturn, queryOptions);
+ return this->query(ptr, nsOrUuid, query, fieldsToReturn, queryOptions);
}
unsigned long long DBClientBase::query(stdx::function<void(DBClientCursorBatchIterator&)> f,
- const string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
Query query,
const BSONObj* fieldsToReturn,
int queryOptions) {
// mask options
queryOptions &= (int)(QueryOption_NoCursorTimeout | QueryOption_SlaveOk);
- unique_ptr<DBClientCursor> c(this->query(ns, query, 0, 0, fieldsToReturn, queryOptions));
+ unique_ptr<DBClientCursor> c(this->query(nsOrUuid, query, 0, 0, fieldsToReturn, queryOptions));
uassert(16090, "socket error for mapping query", c.get());
unsigned long long n = 0;
diff --git a/src/mongo/client/dbclient_base.h b/src/mongo/client/dbclient_base.h
index ef8333fcf34..ffb4c9d0640 100644
--- a/src/mongo/client/dbclient_base.h
+++ b/src/mongo/client/dbclient_base.h
@@ -71,7 +71,7 @@ std::string nsGetCollection(const std::string& ns);
* them as "final" or "override" as appropriate.
*/
class DBClientQueryInterface {
- virtual std::unique_ptr<DBClientCursor> query(const std::string& ns,
+ virtual std::unique_ptr<DBClientCursor> query(const NamespaceStringOrUUID& nsOrUuid,
Query query,
int nToReturn = 0,
int nToSkip = 0,
@@ -80,13 +80,13 @@ class DBClientQueryInterface {
int batchSize = 0) = 0;
virtual unsigned long long query(stdx::function<void(const BSONObj&)> f,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
Query query,
const BSONObj* fieldsToReturn = 0,
int queryOptions = 0) = 0;
virtual unsigned long long query(stdx::function<void(DBClientCursorBatchIterator&)> f,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
Query query,
const BSONObj* fieldsToReturn = 0,
int queryOptions = 0) = 0;
@@ -572,7 +572,7 @@ public:
@return cursor. 0 if error (connection failure)
@throws AssertionException
*/
- std::unique_ptr<DBClientCursor> query(const std::string& ns,
+ std::unique_ptr<DBClientCursor> query(const NamespaceStringOrUUID& nsOrUuid,
Query query,
int nToReturn = 0,
int nToSkip = 0,
@@ -590,13 +590,13 @@ public:
blocks, perhaps to avoid granular locking and such.
*/
unsigned long long query(stdx::function<void(const BSONObj&)> f,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
Query query,
const BSONObj* fieldsToReturn = 0,
int queryOptions = 0) final;
unsigned long long query(stdx::function<void(DBClientCursorBatchIterator&)> f,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
Query query,
const BSONObj* fieldsToReturn = 0,
int queryOptions = 0) override;
diff --git a/src/mongo/client/dbclient_connection.cpp b/src/mongo/client/dbclient_connection.cpp
index b8f9e93e7de..870e98f1920 100644
--- a/src/mongo/client/dbclient_connection.cpp
+++ b/src/mongo/client/dbclient_connection.cpp
@@ -477,19 +477,19 @@ uint64_t DBClientConnection::getSockCreationMicroSec() const {
}
unsigned long long DBClientConnection::query(stdx::function<void(DBClientCursorBatchIterator&)> f,
- const string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
Query query,
const BSONObj* fieldsToReturn,
int queryOptions) {
if (!(availableOptions() & QueryOption_Exhaust)) {
- return DBClientBase::query(f, ns, query, fieldsToReturn, queryOptions);
+ return DBClientBase::query(f, nsOrUuid, query, fieldsToReturn, queryOptions);
}
// mask options
queryOptions &= (int)(QueryOption_NoCursorTimeout | QueryOption_SlaveOk);
queryOptions |= (int)QueryOption_Exhaust;
- unique_ptr<DBClientCursor> c(this->query(ns, query, 0, 0, fieldsToReturn, queryOptions));
+ unique_ptr<DBClientCursor> c(this->query(nsOrUuid, query, 0, 0, fieldsToReturn, queryOptions));
uassert(13386, "socket error for mapping query", c.get());
unsigned long long n = 0;
diff --git a/src/mongo/client/dbclient_connection.h b/src/mongo/client/dbclient_connection.h
index 39b1ff057cc..7ccceb07590 100644
--- a/src/mongo/client/dbclient_connection.h
+++ b/src/mongo/client/dbclient_connection.h
@@ -146,7 +146,7 @@ public:
*/
void logout(const std::string& dbname, BSONObj& info) override;
- std::unique_ptr<DBClientCursor> query(const std::string& ns,
+ std::unique_ptr<DBClientCursor> query(const NamespaceStringOrUUID& nsOrUuid,
Query query = Query(),
int nToReturn = 0,
int nToSkip = 0,
@@ -155,11 +155,11 @@ public:
int batchSize = 0) override {
checkConnection();
return DBClientBase::query(
- ns, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
+ nsOrUuid, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
}
unsigned long long query(stdx::function<void(DBClientCursorBatchIterator&)> f,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
Query query,
const BSONObj* fieldsToReturn,
int queryOptions) override;
diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp
index 2d6ea826c42..ff9ef56c812 100644
--- a/src/mongo/client/dbclient_cursor.cpp
+++ b/src/mongo/client/dbclient_cursor.cpp
@@ -451,7 +451,7 @@ void DBClientCursor::attach(AScopedConnection* conn) {
}
DBClientCursor::DBClientCursor(DBClientBase* client,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
const BSONObj& query,
int nToReturn,
int nToSkip,
@@ -459,7 +459,7 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
int queryOptions,
int batchSize)
: DBClientCursor(client,
- ns,
+ nsOrUuid,
query,
0, // cursorId
nToReturn,
@@ -470,13 +470,13 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
{}) {}
DBClientCursor::DBClientCursor(DBClientBase* client,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
long long cursorId,
int nToReturn,
int queryOptions,
std::vector<BSONObj> initialBatch)
: DBClientCursor(client,
- ns,
+ nsOrUuid,
BSONObj(), // query
cursorId,
nToReturn,
@@ -487,7 +487,7 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
std::move(initialBatch)) {} // batchSize
DBClientCursor::DBClientCursor(DBClientBase* client,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
const BSONObj& query,
long long cursorId,
int nToReturn,
@@ -499,8 +499,8 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
: batch{std::move(initialBatch)},
_client(client),
_originalHost(_client->getServerAddress()),
- ns(ns),
- _isCommand(nsIsFull(ns) ? nsToCollectionSubstring(ns) == "$cmd" : false),
+ ns(nsOrUuid.nss() ? *nsOrUuid.nss() : NamespaceString(nsOrUuid.dbname())),
+ _isCommand(ns.isCommand()),
query(query),
nToReturn(nToReturn),
haveLimit(nToReturn > 0 && !(queryOptions & QueryOption_CursorTailable)),
diff --git a/src/mongo/client/dbclient_cursor.h b/src/mongo/client/dbclient_cursor.h
index 36f5c20452a..7b0f017238b 100644
--- a/src/mongo/client/dbclient_cursor.h
+++ b/src/mongo/client/dbclient_cursor.h
@@ -142,7 +142,7 @@ public:
enum { QueryOptionLocal_forceOpQuery = 1 << 30 };
DBClientCursor(DBClientBase* client,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
const BSONObj& query,
int nToReturn,
int nToSkip,
@@ -151,7 +151,7 @@ public:
int bs);
DBClientCursor(DBClientBase* client,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
long long cursorId,
int nToReturn,
int options,
@@ -220,7 +220,7 @@ public:
private:
DBClientCursor(DBClientBase* client,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
const BSONObj& query,
long long cursorId,
int nToReturn,
diff --git a/src/mongo/client/dbclient_mockcursor.h b/src/mongo/client/dbclient_mockcursor.h
index db711d738ea..6ebd87f52ef 100644
--- a/src/mongo/client/dbclient_mockcursor.h
+++ b/src/mongo/client/dbclient_mockcursor.h
@@ -36,7 +36,7 @@ namespace mongo {
class DBClientMockCursor : public DBClientCursor {
public:
DBClientMockCursor(mongo::DBClientBase* client, const BSONArray& mockCollection)
- : mongo::DBClientCursor(client, "", 0, 0, 0),
+ : mongo::DBClientCursor(client, NamespaceString(), 0, 0, 0),
_collectionArray(mockCollection),
_iter(_collectionArray) {}
diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp
index 2695730ab6b..11c6fba051d 100644
--- a/src/mongo/client/dbclient_rs.cpp
+++ b/src/mongo/client/dbclient_rs.cpp
@@ -504,7 +504,7 @@ void DBClientReplicaSet::update(const string& ns, Query query, BSONObj obj, int
return checkMaster()->update(ns, query, obj, flags);
}
-unique_ptr<DBClientCursor> DBClientReplicaSet::query(const string& ns,
+unique_ptr<DBClientCursor> DBClientReplicaSet::query(const NamespaceStringOrUUID& nsOrUuid,
Query query,
int nToReturn,
int nToSkip,
@@ -512,6 +512,8 @@ unique_ptr<DBClientCursor> DBClientReplicaSet::query(const string& ns,
int queryOptions,
int batchSize) {
shared_ptr<ReadPreferenceSetting> readPref(_extractReadPref(query.obj, queryOptions));
+ invariant(nsOrUuid.nss());
+ const string ns = nsOrUuid.nss()->ns();
if (_isSecondaryQuery(ns, query.obj, *readPref)) {
LOG(3) << "dbclient_rs query using secondary or tagged node selection in "
<< _getMonitor()->getName() << ", read pref is " << readPref->toString()
@@ -533,7 +535,7 @@ unique_ptr<DBClientCursor> DBClientReplicaSet::query(const string& ns,
}
unique_ptr<DBClientCursor> cursor = conn->query(
- ns, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
+ nsOrUuid, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
return checkSlaveQueryResult(std::move(cursor));
} catch (const DBException& ex) {
@@ -556,7 +558,7 @@ unique_ptr<DBClientCursor> DBClientReplicaSet::query(const string& ns,
LOG(3) << "dbclient_rs query to primary node in " << _getMonitor()->getName() << endl;
return checkMaster()->query(
- ns, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
+ nsOrUuid, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
}
BSONObj DBClientReplicaSet::findOne(const string& ns,
diff --git a/src/mongo/client/dbclient_rs.h b/src/mongo/client/dbclient_rs.h
index fb7fb748079..e10acced220 100644
--- a/src/mongo/client/dbclient_rs.h
+++ b/src/mongo/client/dbclient_rs.h
@@ -83,7 +83,7 @@ public:
// ----------- simple functions --------------
/** throws userassertion "no master found" */
- std::unique_ptr<DBClientCursor> query(const std::string& ns,
+ std::unique_ptr<DBClientCursor> query(const NamespaceStringOrUUID& nsOrUuid,
Query query,
int nToReturn = 0,
int nToSkip = 0,
diff --git a/src/mongo/client/dbclient_rs_test.cpp b/src/mongo/client/dbclient_rs_test.cpp
index d0fec97f3d2..799713d98c1 100644
--- a/src/mongo/client/dbclient_rs_test.cpp
+++ b/src/mongo/client/dbclient_rs_test.cpp
@@ -128,7 +128,7 @@ TEST_F(BasicRS, QueryPrimary) {
query.readPref(mongo::ReadPreference::PrimaryOnly, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getPrimary(), doc[HostField.name()].str());
}
@@ -145,7 +145,7 @@ TEST_F(BasicRS, QuerySecondaryOnly) {
query.readPref(mongo::ReadPreference::SecondaryOnly, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getSecondaries().front(), doc[HostField.name()].str());
}
@@ -166,7 +166,7 @@ TEST_F(BasicRS, QueryPrimaryPreferred) {
query.readPref(mongo::ReadPreference::PrimaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getPrimary(), doc[HostField.name()].str());
}
@@ -186,7 +186,7 @@ TEST_F(BasicRS, QuerySecondaryPreferred) {
query.readPref(mongo::ReadPreference::SecondaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getSecondaries().front(), doc[HostField.name()].str());
}
@@ -245,7 +245,7 @@ TEST_F(AllNodesDown, QueryPrimary) {
Query query;
query.readPref(mongo::ReadPreference::PrimaryOnly, BSONArray());
- ASSERT_THROWS(replConn.query(IdentityNS, query), AssertionException);
+ ASSERT_THROWS(replConn.query(NamespaceString(IdentityNS), query), AssertionException);
}
TEST_F(AllNodesDown, CommandPrimary) {
@@ -258,7 +258,7 @@ TEST_F(AllNodesDown, QuerySecondaryOnly) {
Query query;
query.readPref(mongo::ReadPreference::SecondaryOnly, BSONArray());
- ASSERT_THROWS(replConn.query(IdentityNS, query), AssertionException);
+ ASSERT_THROWS(replConn.query(NamespaceString(IdentityNS), query), AssertionException);
}
TEST_F(AllNodesDown, CommandSecondaryOnly) {
@@ -271,7 +271,7 @@ TEST_F(AllNodesDown, QueryPrimaryPreferred) {
Query query;
query.readPref(mongo::ReadPreference::PrimaryPreferred, BSONArray());
- ASSERT_THROWS(replConn.query(IdentityNS, query), AssertionException);
+ ASSERT_THROWS(replConn.query(NamespaceString(IdentityNS), query), AssertionException);
}
TEST_F(AllNodesDown, CommandPrimaryPreferred) {
@@ -284,7 +284,7 @@ TEST_F(AllNodesDown, QuerySecondaryPreferred) {
Query query;
query.readPref(mongo::ReadPreference::SecondaryPreferred, BSONArray());
- ASSERT_THROWS(replConn.query(IdentityNS, query), AssertionException);
+ ASSERT_THROWS(replConn.query(NamespaceString(IdentityNS), query), AssertionException);
}
TEST_F(AllNodesDown, CommandSecondaryPreferred) {
@@ -297,7 +297,7 @@ TEST_F(AllNodesDown, QueryNearest) {
Query query;
query.readPref(mongo::ReadPreference::Nearest, BSONArray());
- ASSERT_THROWS(replConn.query(IdentityNS, query), AssertionException);
+ ASSERT_THROWS(replConn.query(NamespaceString(IdentityNS), query), AssertionException);
}
TEST_F(AllNodesDown, CommandNearest) {
@@ -338,7 +338,7 @@ TEST_F(PrimaryDown, QueryPrimary) {
Query query;
query.readPref(mongo::ReadPreference::PrimaryOnly, BSONArray());
- ASSERT_THROWS(replConn.query(IdentityNS, query), AssertionException);
+ ASSERT_THROWS(replConn.query(NamespaceString(IdentityNS), query), AssertionException);
}
TEST_F(PrimaryDown, CommandPrimary) {
@@ -353,7 +353,7 @@ TEST_F(PrimaryDown, QuerySecondaryOnly) {
query.readPref(mongo::ReadPreference::SecondaryOnly, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getSecondaries().front(), doc[HostField.name()].str());
}
@@ -371,7 +371,7 @@ TEST_F(PrimaryDown, QueryPrimaryPreferred) {
query.readPref(mongo::ReadPreference::PrimaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getSecondaries().front(), doc[HostField.name()].str());
}
@@ -389,7 +389,7 @@ TEST_F(PrimaryDown, QuerySecondaryPreferred) {
query.readPref(mongo::ReadPreference::SecondaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getSecondaries().front(), doc[HostField.name()].str());
}
@@ -405,7 +405,7 @@ TEST_F(PrimaryDown, Nearest) {
Query query;
query.readPref(mongo::ReadPreference::Nearest, BSONArray());
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getSecondaries().front(), doc[HostField.name()].str());
}
@@ -447,7 +447,7 @@ TEST_F(SecondaryDown, QueryPrimary) {
query.readPref(mongo::ReadPreference::PrimaryOnly, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getPrimary(), doc[HostField.name()].str());
}
@@ -462,7 +462,7 @@ TEST_F(SecondaryDown, QuerySecondaryOnly) {
Query query;
query.readPref(mongo::ReadPreference::SecondaryOnly, BSONArray());
- ASSERT_THROWS(replConn.query(IdentityNS, query), AssertionException);
+ ASSERT_THROWS(replConn.query(NamespaceString(IdentityNS), query), AssertionException);
}
TEST_F(SecondaryDown, CommandSecondaryOnly) {
@@ -477,7 +477,7 @@ TEST_F(SecondaryDown, QueryPrimaryPreferred) {
query.readPref(mongo::ReadPreference::PrimaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getPrimary(), doc[HostField.name()].str());
}
@@ -494,7 +494,7 @@ TEST_F(SecondaryDown, QuerySecondaryPreferred) {
query.readPref(mongo::ReadPreference::SecondaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getPrimary(), doc[HostField.name()].str());
}
@@ -511,7 +511,7 @@ TEST_F(SecondaryDown, QueryNearest) {
query.readPref(mongo::ReadPreference::Nearest, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getPrimary(), doc[HostField.name()].str());
}
@@ -657,7 +657,7 @@ TEST_F(TaggedFiveMemberRS, ConnShouldPinIfSameSettings) {
query.readPref(mongo::ReadPreference::PrimaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
dest = doc[HostField.name()].str();
}
@@ -665,7 +665,7 @@ TEST_F(TaggedFiveMemberRS, ConnShouldPinIfSameSettings) {
{
Query query;
query.readPref(mongo::ReadPreference::PrimaryPreferred, BSONArray());
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
const string newDest = doc[HostField.name()].str();
ASSERT_EQUALS(dest, newDest);
@@ -685,7 +685,7 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfHostMarkedAsFailed) {
query.readPref(mongo::ReadPreference::PrimaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
dest = doc[HostField.name()].str();
}
@@ -699,7 +699,7 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfHostMarkedAsFailed) {
{
Query query;
query.readPref(mongo::ReadPreference::PrimaryPreferred, BSONArray());
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
const string newDest = doc[HostField.name()].str();
ASSERT_NOT_EQUALS(dest, newDest);
@@ -722,7 +722,7 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfDiffMode) {
query.readPref(mongo::ReadPreference::SecondaryPreferred, BSONArray());
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
dest = doc[HostField.name()].str();
ASSERT_NOT_EQUALS(dest, replSet->getPrimary());
@@ -731,7 +731,7 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfDiffMode) {
{
Query query;
query.readPref(mongo::ReadPreference::SecondaryOnly, BSONArray());
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
const string newDest = doc[HostField.name()].str();
ASSERT_NOT_EQUALS(dest, newDest);
@@ -756,7 +756,7 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfDiffTag) {
<< "sf")));
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
dest = doc[HostField.name()].str();
ASSERT_NOT_EQUALS(dest, replSet->getPrimary());
@@ -766,7 +766,7 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfDiffTag) {
Query query;
vector<pair<string, string>> tagSet;
query.readPref(mongo::ReadPreference::SecondaryPreferred, BSON_ARRAY(BSON("group" << 1)));
- unique_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query);
+ unique_ptr<DBClientCursor> cursor = replConn.query(NamespaceString(IdentityNS), query);
BSONObj doc = cursor->next();
const string newDest = doc[HostField.name()].str();
ASSERT_NOT_EQUALS(dest, newDest);
@@ -789,7 +789,7 @@ TEST_F(TaggedFiveMemberRS, SlaveConnReturnsSecConn) {
mongo::DBClientConnection& secConn = replConn.slaveConn();
// Note: IdentityNS contains the name of the server.
- unique_ptr<DBClientCursor> cursor = secConn.query(IdentityNS, Query());
+ unique_ptr<DBClientCursor> cursor = secConn.query(NamespaceString(IdentityNS), Query());
BSONObj doc = cursor->next();
dest = doc[HostField.name()].str();
ASSERT_NOT_EQUALS(dest, replSet->getPrimary());
diff --git a/src/mongo/db/auth/authz_manager_external_state_d.cpp b/src/mongo/db/auth/authz_manager_external_state_d.cpp
index 1454076a12b..11e350ee253 100644
--- a/src/mongo/db/auth/authz_manager_external_state_d.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_d.cpp
@@ -67,7 +67,7 @@ Status AuthzManagerExternalStateMongod::query(
const stdx::function<void(const BSONObj&)>& resultProcessor) {
try {
DBDirectClient client(opCtx);
- client.query(resultProcessor, collectionName.ns(), query, &projection);
+ client.query(resultProcessor, collectionName, query, &projection);
return Status::OK();
} catch (const DBException& e) {
return e.toStatus();
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 2dce75495d9..98c0e5ce7d0 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -327,7 +327,7 @@ void Cloner::copy(OperationContext* opCtx,
{
Lock::TempRelease tempRelease(opCtx->lockState());
_conn->query(stdx::function<void(DBClientCursorBatchIterator&)>(f),
- from_collection.ns(),
+ from_collection,
query,
0,
options);
diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp
index ec92a4c5a60..29452ea8c1a 100644
--- a/src/mongo/db/commands/dbcommands_d.cpp
+++ b/src/mongo/db/commands/dbcommands_d.cpp
@@ -347,7 +347,7 @@ public:
DBDirectClient client(opCtx);
Query q(query);
q.sort(sort);
- unique_ptr<DBClientCursor> c = client.query(ns, q);
+ unique_ptr<DBClientCursor> c = client.query(NamespaceString(ns), q);
while (c->more()) {
log() << c->nextSafe();
}
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 0d015b896f3..7f93d336b76 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -725,7 +725,7 @@ long long State::postProcessCollectionNonAtomic(OperationContext* opCtx,
curOp->setMessage_inlock(
"m/r: merge post processing", "M/R Merge Post Processing Progress", count);
}
- unique_ptr<DBClientCursor> cursor = _db.query(_config.tempNamespace.ns(), BSONObj());
+ unique_ptr<DBClientCursor> cursor = _db.query(_config.tempNamespace, BSONObj());
while (cursor->more()) {
Lock::DBLock lock(opCtx, _config.outputOptions.finalNamespace.db(), MODE_X);
BSONObj o = cursor->nextSafe();
@@ -744,7 +744,7 @@ long long State::postProcessCollectionNonAtomic(OperationContext* opCtx,
curOp->setMessage_inlock(
"m/r: reduce post processing", "M/R Reduce Post Processing Progress", count);
}
- unique_ptr<DBClientCursor> cursor = _db.query(_config.tempNamespace.ns(), BSONObj());
+ unique_ptr<DBClientCursor> cursor = _db.query(_config.tempNamespace, BSONObj());
while (cursor->more()) {
// This must be global because we may write across different databases.
Lock::GlobalWrite lock(opCtx);
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp
index 2fca9a9973f..603e5519b1d 100644
--- a/src/mongo/db/commands/user_management_commands.cpp
+++ b/src/mongo/db/commands/user_management_commands.cpp
@@ -252,7 +252,7 @@ Status queryAuthzDocument(OperationContext* opCtx,
const stdx::function<void(const BSONObj&)>& resultProcessor) {
try {
DBDirectClient client(opCtx);
- client.query(resultProcessor, collectionName.ns(), query, &projection);
+ client.query(resultProcessor, collectionName, query, &projection);
return Status::OK();
} catch (const DBException& e) {
return e.toStatus();
@@ -1383,12 +1383,8 @@ public:
CommandHelpers::appendSimpleCommandStatus(bodyBuilder, true);
bodyBuilder.doneFast();
auto response = CursorResponse::parseFromBSONThrowing(replyBuilder.releaseBody());
- DBClientCursor cursor(&client,
- response.getNSS().toString(),
- response.getCursorId(),
- 0,
- 0,
- response.releaseBatch());
+ DBClientCursor cursor(
+ &client, response.getNSS(), response.getCursorId(), 0, 0, response.releaseBatch());
while (cursor.more()) {
usersArrayBuilder.append(cursor.next());
diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp
index e349befb194..eef751d72c3 100644
--- a/src/mongo/db/dbdirectclient.cpp
+++ b/src/mongo/db/dbdirectclient.cpp
@@ -159,7 +159,7 @@ void DBDirectClient::say(Message& toSend, bool isRetry, string* actualServer) {
invariant(dbResponse.response.empty());
}
-unique_ptr<DBClientCursor> DBDirectClient::query(const string& ns,
+unique_ptr<DBClientCursor> DBDirectClient::query(const NamespaceStringOrUUID& nsOrUuid,
Query query,
int nToReturn,
int nToSkip,
@@ -167,7 +167,7 @@ unique_ptr<DBClientCursor> DBDirectClient::query(const string& ns,
int queryOptions,
int batchSize) {
return DBClientBase::query(
- ns, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
+ nsOrUuid, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
}
unsigned long long DBDirectClient::count(
diff --git a/src/mongo/db/dbdirectclient.h b/src/mongo/db/dbdirectclient.h
index b8f3ebc14d6..929980743b5 100644
--- a/src/mongo/db/dbdirectclient.h
+++ b/src/mongo/db/dbdirectclient.h
@@ -57,7 +57,7 @@ public:
// XXX: is this valid or useful?
void setOpCtx(OperationContext* opCtx);
- virtual std::unique_ptr<DBClientCursor> query(const std::string& ns,
+ virtual std::unique_ptr<DBClientCursor> query(const NamespaceStringOrUUID& nsOrUuid,
Query query,
int nToReturn = 0,
int nToSkip = 0,
diff --git a/src/mongo/db/repl/oplog_interface_remote.cpp b/src/mongo/db/repl/oplog_interface_remote.cpp
index e7e66beb2a4..ece945276e7 100644
--- a/src/mongo/db/repl/oplog_interface_remote.cpp
+++ b/src/mongo/db/repl/oplog_interface_remote.cpp
@@ -81,8 +81,9 @@ std::string OplogInterfaceRemote::toString() const {
std::unique_ptr<OplogInterface::Iterator> OplogInterfaceRemote::makeIterator() const {
const Query query = Query().sort(BSON("$natural" << -1));
const BSONObj fields = BSON("ts" << 1 << "h" << 1);
- return std::unique_ptr<OplogInterface::Iterator>(new OplogIteratorRemote(
- _getConnection()->query(_collectionName, query, 0, 0, &fields, 0, _batchSize)));
+ return std::unique_ptr<OplogInterface::Iterator>(
+ new OplogIteratorRemote(_getConnection()->query(
+ NamespaceString(_collectionName), query, 0, 0, &fields, 0, _batchSize)));
}
HostAndPort OplogInterfaceRemote::hostAndPort() const {
diff --git a/src/mongo/db/repl/oplogreader.cpp b/src/mongo/db/repl/oplogreader.cpp
index 6ae234cb57b..cb592dbcd9d 100644
--- a/src/mongo/db/repl/oplogreader.cpp
+++ b/src/mongo/db/repl/oplogreader.cpp
@@ -94,7 +94,8 @@ void OplogReader::tailCheck() {
void OplogReader::tailingQuery(const char* ns, const BSONObj& query) {
verify(!haveCursor());
LOG(2) << ns << ".find(" << redact(query) << ')' << endl;
- cursor.reset(_conn->query(ns, query, 0, 0, nullptr, _tailingQueryOptions).release());
+ cursor.reset(
+ _conn->query(NamespaceString(ns), query, 0, 0, nullptr, _tailingQueryOptions).release());
}
} // namespace repl
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index db74d511246..16d396b63eb 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -105,7 +105,7 @@ public:
void startup(OperationContext* opCtx) final {
_client = std::make_unique<DBDirectClient>(opCtx);
- _cursor = _client->query(NamespaceString::kRsOplogNamespace.ns(),
+ _cursor = _client->query(NamespaceString::kRsOplogNamespace,
QUERY("ts" << BSON("$gte" << _oplogApplicationStartPoint)),
/*batchSize*/ 0,
/*skip*/ 0,
diff --git a/src/mongo/db/repl/roll_back_local_operations_test.cpp b/src/mongo/db/repl/roll_back_local_operations_test.cpp
index 6e7c4f1062b..1680862f5fa 100644
--- a/src/mongo/db/repl/roll_back_local_operations_test.cpp
+++ b/src/mongo/db/repl/roll_back_local_operations_test.cpp
@@ -412,7 +412,7 @@ public:
using DBClientConnection::query;
- std::unique_ptr<DBClientCursor> query(const std::string& ns,
+ std::unique_ptr<DBClientCursor> query(const NamespaceStringOrUUID& nsOrUuid,
Query query,
int nToReturn,
int nToSkip,
diff --git a/src/mongo/db/s/chunk_splitter.cpp b/src/mongo/db/s/chunk_splitter.cpp
index 474cc3935e1..d19042d2a37 100644
--- a/src/mongo/db/s/chunk_splitter.cpp
+++ b/src/mongo/db/s/chunk_splitter.cpp
@@ -168,7 +168,7 @@ BSONObj findExtremeKeyForShard(OperationContext* opCtx,
// Splitting close to the lower bound means that the split point will be the
// upper bound. Chunk range upper bounds are exclusive so skip a document to
// make the lower half of the split end up with a single document.
- std::unique_ptr<DBClientCursor> cursor = client.query(nss.ns(),
+ std::unique_ptr<DBClientCursor> cursor = client.query(nss,
q,
1, /* nToReturn */
1 /* nToSkip */);
diff --git a/src/mongo/db/s/session_catalog_migration_source.cpp b/src/mongo/db/s/session_catalog_migration_source.cpp
index 79c12ccd75b..45d4dc6c813 100644
--- a/src/mongo/db/s/session_catalog_migration_source.cpp
+++ b/src/mongo/db/s/session_catalog_migration_source.cpp
@@ -126,7 +126,7 @@ SessionCatalogMigrationSource::SessionCatalogMigrationSource(OperationContext* o
query.sort(BSON("_id" << 1));
DBDirectClient client(opCtx);
- auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace.ns(), query);
+ auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace, query);
while (cursor->more()) {
auto nextSession = SessionTxnRecord::parse(
diff --git a/src/mongo/db/s/shard_metadata_util.cpp b/src/mongo/db/s/shard_metadata_util.cpp
index b2f0c9352c9..074e74cd8b3 100644
--- a/src/mongo/db/s/shard_metadata_util.cpp
+++ b/src/mongo/db/s/shard_metadata_util.cpp
@@ -141,7 +141,7 @@ StatusWith<ShardCollectionType> readShardCollectionsEntry(OperationContext* opCt
try {
DBDirectClient client(opCtx);
std::unique_ptr<DBClientCursor> cursor =
- client.query(NamespaceString::kShardConfigCollectionsNamespace.ns(), fullQuery, 1);
+ client.query(NamespaceString::kShardConfigCollectionsNamespace, fullQuery, 1);
if (!cursor) {
return Status(ErrorCodes::OperationFailed,
str::stream() << "Failed to establish a cursor for reading "
@@ -174,7 +174,7 @@ StatusWith<ShardDatabaseType> readShardDatabasesEntry(OperationContext* opCtx, S
try {
DBDirectClient client(opCtx);
std::unique_ptr<DBClientCursor> cursor =
- client.query(NamespaceString::kShardConfigDatabasesNamespace.ns(), fullQuery, 1);
+ client.query(NamespaceString::kShardConfigDatabasesNamespace, fullQuery, 1);
if (!cursor) {
return Status(ErrorCodes::OperationFailed,
str::stream() << "Failed to establish a cursor for reading "
@@ -303,7 +303,7 @@ StatusWith<std::vector<ChunkType>> readShardChunks(OperationContext* opCtx,
const std::string chunkMetadataNs = ChunkType::ShardNSPrefix + nss.ns();
std::unique_ptr<DBClientCursor> cursor =
- client.query(chunkMetadataNs, fullQuery, limit.get_value_or(0));
+ client.query(NamespaceString(chunkMetadataNs), fullQuery, limit.get_value_or(0));
uassert(ErrorCodes::OperationFailed,
str::stream() << "Failed to establish a cursor for reading " << chunkMetadataNs
<< " from local storage",
diff --git a/src/mongo/db/s/shard_metadata_util_test.cpp b/src/mongo/db/s/shard_metadata_util_test.cpp
index 2b3b9fe5221..3928ab6f364 100644
--- a/src/mongo/db/s/shard_metadata_util_test.cpp
+++ b/src/mongo/db/s/shard_metadata_util_test.cpp
@@ -145,8 +145,7 @@ struct ShardMetadataUtilTest : public ShardServerTestFixture {
<< chunk.getMax()));
query.readPref(ReadPreference::Nearest, BSONArray());
- std::unique_ptr<DBClientCursor> cursor =
- client.query(chunkMetadataNss.ns(), query, 1);
+ std::unique_ptr<DBClientCursor> cursor = client.query(chunkMetadataNss, query, 1);
ASSERT(cursor);
ASSERT(cursor->more());
diff --git a/src/mongo/db/session_test.cpp b/src/mongo/db/session_test.cpp
index 1b8845011c3..38ac8918865 100644
--- a/src/mongo/db/session_test.cpp
+++ b/src/mongo/db/session_test.cpp
@@ -206,7 +206,7 @@ protected:
repl::OpTime opTime,
boost::optional<DurableTxnStateEnum> txnState) {
DBDirectClient client(opCtx());
- auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace.ns(),
+ auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace,
{BSON("_id" << session->getSessionId().toBSON())});
ASSERT(cursor);
ASSERT(cursor->more());
@@ -243,7 +243,7 @@ TEST_F(SessionTest, SessionEntryNotWrittenOnBegin) {
ASSERT(session.getLastWriteOpTime(txnNum).isNull());
DBDirectClient client(opCtx());
- auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace.ns(),
+ auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace,
{BSON("_id" << sessionId.toBSON())});
ASSERT(cursor);
ASSERT(!cursor->more());
@@ -260,7 +260,7 @@ TEST_F(SessionTest, SessionEntryWrittenAtFirstWrite) {
const auto opTime = writeTxnRecord(&session, txnNum, 0, {}, boost::none);
DBDirectClient client(opCtx());
- auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace.ns(),
+ auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace,
{BSON("_id" << sessionId.toBSON())});
ASSERT(cursor);
ASSERT(cursor->more());
@@ -284,7 +284,7 @@ TEST_F(SessionTest, StartingNewerTransactionUpdatesThePersistedSession) {
const auto secondOpTime = writeTxnRecord(&session, 200, 1, firstOpTime, boost::none);
DBDirectClient client(opCtx());
- auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace.ns(),
+ auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace,
{BSON("_id" << sessionId.toBSON())});
ASSERT(cursor);
ASSERT(cursor->more());
diff --git a/src/mongo/db/transaction_reaper.cpp b/src/mongo/db/transaction_reaper.cpp
index ed60be0aedb..2f7df78d9cd 100644
--- a/src/mongo/db/transaction_reaper.cpp
+++ b/src/mongo/db/transaction_reaper.cpp
@@ -126,7 +126,7 @@ public:
auto query = makeQuery(opCtx->getServiceContext()->getFastClockSource()->now());
auto cursor = client.query(
- NamespaceString::kSessionTransactionsTableNamespace.ns(), query, 0, 0, &kIdProjection);
+ NamespaceString::kSessionTransactionsTableNamespace, query, 0, 0, &kIdProjection);
while (cursor->more()) {
auto transactionSession = SessionsCollectionFetchResultIndividualResult::parse(
diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp
index 62c529da26b..57666d5e899 100644
--- a/src/mongo/dbtests/clienttests.cpp
+++ b/src/mongo/dbtests/clienttests.cpp
@@ -150,7 +150,8 @@ public:
ASSERT_OK(dbtests::createIndex(&opCtx, ns(), BSON("a" << 1 << "b" << 1)));
- unique_ptr<DBClientCursor> c = db.query(ns(), Query().sort(BSON("a" << 1 << "b" << 1)));
+ unique_ptr<DBClientCursor> c =
+ db.query(NamespaceString(ns()), Query().sort(BSON("a" << 1 << "b" << 1)));
ASSERT_EQUALS(1111, c->itcount());
}
};
@@ -167,7 +168,8 @@ public:
db.insert(ns(), BSON("i" << i));
}
- unique_ptr<DBClientCursor> c = db.query(ns(), Query().sort(BSON("i" << 1)));
+ unique_ptr<DBClientCursor> c =
+ db.query(NamespaceString(ns()), Query().sort(BSON("i" << 1)));
BSONObj o = c->next();
ASSERT(c->more());
diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp
index 975a446894a..959b62db3e3 100644
--- a/src/mongo/dbtests/dbhelper_tests.cpp
+++ b/src/mongo/dbtests/dbhelper_tests.cpp
@@ -75,7 +75,8 @@ private:
BSONArray docs(OperationContext* opCtx) const {
DBDirectClient client(opCtx);
- unique_ptr<DBClientCursor> cursor = client.query(ns, Query().hint(BSON("_id" << 1)));
+ unique_ptr<DBClientCursor> cursor =
+ client.query(NamespaceString(ns), Query().hint(BSON("_id" << 1)));
BSONArrayBuilder bab;
while (cursor->more()) {
bab << cursor->next();
diff --git a/src/mongo/dbtests/directclienttests.cpp b/src/mongo/dbtests/directclienttests.cpp
index 2d278ac3126..8f13d8d0f34 100644
--- a/src/mongo/dbtests/directclienttests.cpp
+++ b/src/mongo/dbtests/directclienttests.cpp
@@ -142,7 +142,7 @@ public:
OperationContext& opCtx = *opCtxPtr;
DBDirectClient client(&opCtx);
- ASSERT_THROWS_CODE(client.query("", Query(), 1)->nextSafe(),
+ ASSERT_THROWS_CODE(client.query(NamespaceString(), Query(), 1)->nextSafe(),
AssertionException,
ErrorCodes::InvalidNamespace);
}
diff --git a/src/mongo/dbtests/logical_sessions_tests.cpp b/src/mongo/dbtests/logical_sessions_tests.cpp
index 07b3f892531..582fb836438 100644
--- a/src/mongo/dbtests/logical_sessions_tests.cpp
+++ b/src/mongo/dbtests/logical_sessions_tests.cpp
@@ -70,7 +70,7 @@ BSONObj lsidQuery(const LogicalSessionId& lsid) {
StatusWith<LogicalSessionRecord> fetchRecord(OperationContext* opCtx,
const LogicalSessionId& lsid) {
DBDirectClient client(opCtx);
- auto cursor = client.query(kTestNS.toString(), lsidQuery(lsid), 1);
+ auto cursor = client.query(NamespaceString(kTestNS), lsidQuery(lsid), 1);
if (!cursor->more()) {
return {ErrorCodes::NoSuchSession, "No matching record in the sessions collection"};
}
diff --git a/src/mongo/dbtests/mock/mock_dbclient_connection.cpp b/src/mongo/dbtests/mock/mock_dbclient_connection.cpp
index 52426ad4818..b7c477227f9 100644
--- a/src/mongo/dbtests/mock/mock_dbclient_connection.cpp
+++ b/src/mongo/dbtests/mock/mock_dbclient_connection.cpp
@@ -74,18 +74,22 @@ std::pair<rpc::UniqueReply, DBClientBase*> MockDBClientConnection::runCommandWit
}
-std::unique_ptr<mongo::DBClientCursor> MockDBClientConnection::query(const string& ns,
- mongo::Query query,
- int nToReturn,
- int nToSkip,
- const BSONObj* fieldsToReturn,
- int queryOptions,
- int batchSize) {
+std::unique_ptr<mongo::DBClientCursor> MockDBClientConnection::query(
+ const NamespaceStringOrUUID& nsOrUuid,
+ mongo::Query query,
+ int nToReturn,
+ int nToSkip,
+ const BSONObj* fieldsToReturn,
+ int queryOptions,
+ int batchSize) {
+ // The mock client does not support UUIDs.
+ invariant(nsOrUuid.nss());
+
checkConnection();
try {
mongo::BSONArray result(_remoteServer->query(_remoteServerInstanceID,
- ns,
+ nsOrUuid.nss()->ns(),
query,
nToReturn,
nToSkip,
@@ -123,7 +127,7 @@ string MockDBClientConnection::toString() const {
unsigned long long MockDBClientConnection::query(
stdx::function<void(mongo::DBClientCursorBatchIterator&)> f,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
mongo::Query query,
const mongo::BSONObj* fieldsToReturn,
int queryOptions) {
diff --git a/src/mongo/dbtests/mock/mock_dbclient_connection.h b/src/mongo/dbtests/mock/mock_dbclient_connection.h
index 2e78ae67799..0871c82fcfc 100644
--- a/src/mongo/dbtests/mock/mock_dbclient_connection.h
+++ b/src/mongo/dbtests/mock/mock_dbclient_connection.h
@@ -70,7 +70,7 @@ public:
using DBClientBase::runCommandWithTarget;
std::pair<rpc::UniqueReply, DBClientBase*> runCommandWithTarget(OpMsgRequest request) override;
- std::unique_ptr<mongo::DBClientCursor> query(const std::string& ns,
+ std::unique_ptr<mongo::DBClientCursor> query(const NamespaceStringOrUUID& nsOrUuid,
mongo::Query query = mongo::Query(),
int nToReturn = 0,
int nToSkip = 0,
@@ -101,7 +101,7 @@ public:
//
unsigned long long query(stdx::function<void(mongo::DBClientCursorBatchIterator&)> f,
- const std::string& ns,
+ const NamespaceStringOrUUID& nsOrUuid,
mongo::Query query,
const mongo::BSONObj* fieldsToReturn = 0,
int queryOptions = 0) override;
diff --git a/src/mongo/dbtests/mock/mock_dbclient_cursor.cpp b/src/mongo/dbtests/mock/mock_dbclient_cursor.cpp
index 13eaddbb855..f0fb2499adb 100644
--- a/src/mongo/dbtests/mock/mock_dbclient_cursor.cpp
+++ b/src/mongo/dbtests/mock/mock_dbclient_cursor.cpp
@@ -34,7 +34,7 @@
namespace mongo {
MockDBClientCursor::MockDBClientCursor(mongo::DBClientBase* client,
const mongo::BSONArray& resultSet)
- : mongo::DBClientCursor(client, "", 0, 0, 0) {
+ : mongo::DBClientCursor(client, NamespaceString(), 0, 0, 0) {
_resultSet = resultSet.copy();
_cursor.reset(new mongo::DBClientMockCursor(client, BSONArray(_resultSet)));
}
diff --git a/src/mongo/dbtests/mock_dbclient_conn_test.cpp b/src/mongo/dbtests/mock_dbclient_conn_test.cpp
index cc90aa3586a..2794292e25b 100644
--- a/src/mongo/dbtests/mock_dbclient_conn_test.cpp
+++ b/src/mongo/dbtests/mock_dbclient_conn_test.cpp
@@ -45,6 +45,7 @@ using mongo::BSONObj;
using mongo::ConnectionString;
using mongo::MockDBClientConnection;
using mongo::MockRemoteDBServer;
+using mongo::NamespaceString;
using mongo::Query;
using std::string;
@@ -67,14 +68,14 @@ TEST(MockDBClientConnTest, QueryCount) {
MockDBClientConnection conn(&server);
ASSERT_EQUALS(0U, server.getQueryCount());
- conn.query("foo.bar");
+ conn.query(NamespaceString("foo.bar"));
}
ASSERT_EQUALS(1U, server.getQueryCount());
{
MockDBClientConnection conn(&server);
- conn.query("foo.bar");
+ conn.query(NamespaceString("foo.bar"));
ASSERT_EQUALS(2U, server.getQueryCount());
}
}
@@ -85,7 +86,7 @@ TEST(MockDBClientConnTest, InsertAndQuery) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(!cursor->more());
server.insert(ns, BSON("x" << 1));
@@ -94,7 +95,7 @@ TEST(MockDBClientConnTest, InsertAndQuery) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -110,7 +111,7 @@ TEST(MockDBClientConnTest, InsertAndQuery) {
// Make sure that repeated calls will still give you the same result
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -132,7 +133,7 @@ TEST(MockDBClientConnTest, InsertAndQueryTwice) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -143,7 +144,7 @@ TEST(MockDBClientConnTest, InsertAndQueryTwice) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -163,7 +164,7 @@ TEST(MockDBClientConnTest, QueryWithNoResults) {
server.insert(ns, BSON("x" << 1));
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query("other.ns");
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString("other.ns"));
ASSERT(!cursor->more());
}
@@ -194,7 +195,7 @@ TEST(MockDBClientConnTest, MultiNSInsertAndQuery) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns1);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns1));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -209,7 +210,7 @@ TEST(MockDBClientConnTest, MultiNSInsertAndQuery) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns2);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns2));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -228,7 +229,7 @@ TEST(MockDBClientConnTest, MultiNSInsertAndQuery) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns3);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns3));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -244,7 +245,7 @@ TEST(MockDBClientConnTest, SimpleRemove) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(!cursor->more());
conn.insert(ns, BSON("x" << 1));
@@ -258,7 +259,7 @@ TEST(MockDBClientConnTest, SimpleRemove) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(!cursor->more());
}
@@ -266,7 +267,7 @@ TEST(MockDBClientConnTest, SimpleRemove) {
// Make sure that repeated calls will still give you the same result
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(!cursor->more());
}
@@ -300,13 +301,13 @@ TEST(MockDBClientConnTest, MultiNSRemove) {
MockDBClientConnection conn(&server);
conn.remove(ns2, Query(), false);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns2);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns2));
ASSERT(!cursor->more());
}
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns1);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns1));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -321,7 +322,7 @@ TEST(MockDBClientConnTest, MultiNSRemove) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns3);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns3));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -356,7 +357,7 @@ TEST(MockDBClientConnTest, InsertAfterRemove) {
{
MockDBClientConnection conn(&server);
- std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(ns);
+ std::unique_ptr<mongo::DBClientCursor> cursor = conn.query(NamespaceString(ns));
ASSERT(cursor->more());
BSONObj firstDoc = cursor->next();
@@ -533,7 +534,7 @@ TEST(MockDBClientConnTest, Shutdown) {
server.shutdown();
ASSERT(!server.isRunning());
- ASSERT_THROWS(conn.query("test.user"), mongo::NetworkException);
+ ASSERT_THROWS(conn.query(NamespaceString("test.user")), mongo::NetworkException);
}
{
@@ -555,16 +556,16 @@ TEST(MockDBClientConnTest, Restart) {
// Do some queries and commands then check the counters later that
// new instance still has it
- conn1.query("test.user");
+ conn1.query(NamespaceString("test.user"));
BSONObj response;
conn1.runCommand("test.user", BSON("serverStatus" << 1), response);
server.shutdown();
- ASSERT_THROWS(conn1.query("test.user"), mongo::NetworkException);
+ ASSERT_THROWS(conn1.query(NamespaceString("test.user")), mongo::NetworkException);
// New connections shouldn't work either
MockDBClientConnection conn2(&server);
- ASSERT_THROWS(conn2.query("test.user"), mongo::NetworkException);
+ ASSERT_THROWS(conn2.query(NamespaceString("test.user")), mongo::NetworkException);
ASSERT_EQUALS(1U, server.getQueryCount());
ASSERT_EQUALS(1U, server.getCmdCount());
@@ -574,12 +575,12 @@ TEST(MockDBClientConnTest, Restart) {
{
MockDBClientConnection conn(&server);
- conn.query("test.user");
+ conn.query(NamespaceString("test.user"));
}
// Old connections still shouldn't work
- ASSERT_THROWS(conn1.query("test.user"), mongo::NetworkException);
- ASSERT_THROWS(conn2.query("test.user"), mongo::NetworkException);
+ ASSERT_THROWS(conn1.query(NamespaceString("test.user")), mongo::NetworkException);
+ ASSERT_THROWS(conn2.query(NamespaceString("test.user")), mongo::NetworkException);
ASSERT_EQUALS(2U, server.getQueryCount());
ASSERT_EQUALS(1U, server.getCmdCount());
@@ -590,7 +591,7 @@ TEST(MockDBClientConnTest, ClearCounter) {
server.setCommandReply("serverStatus", BSON("ok" << 1));
MockDBClientConnection conn(&server);
- conn.query("test.user");
+ conn.query(NamespaceString("test.user"));
BSONObj response;
conn.runCommand("test.user", BSON("serverStatus" << 1), response);
@@ -608,7 +609,7 @@ TEST(MockDBClientConnTest, Delay) {
{
mongo::Timer timer;
- conn.query("x.x");
+ conn.query(NamespaceString("x.x"));
const int nowInMilliSec = timer.millis();
// Use a more lenient lower bound since some platforms like Windows
// don't guarantee that sleeps will not wake up earlier (unlike
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 8e073b3d0b6..239ceae45ab 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -274,7 +274,7 @@ public:
insert(ns, BSON("a" << 1));
insert(ns, BSON("a" << 2));
insert(ns, BSON("a" << 3));
- unique_ptr<DBClientCursor> cursor = _client.query(ns, BSONObj(), 2);
+ unique_ptr<DBClientCursor> cursor = _client.query(NamespaceString(ns), BSONObj(), 2);
long long cursorId = cursor->getCursorId();
cursor->decouple();
cursor.reset();
@@ -310,7 +310,7 @@ public:
}
// Create a cursor on the collection, with a batch size of 200.
- unique_ptr<DBClientCursor> cursor = _client.query(ns, "", 0, 0, 0, 0, 200);
+ unique_ptr<DBClientCursor> cursor = _client.query(NamespaceString(ns), "", 0, 0, 0, 0, 200);
// Count 500 results, spanning a few batches of documents.
for (int i = 0; i < 500; ++i) {
@@ -353,7 +353,7 @@ public:
}
// Create a cursor on the collection, with a batch size of 200.
- unique_ptr<DBClientCursor> cursor = _client.query(ns, "", 0, 0, 0, 0, 200);
+ unique_ptr<DBClientCursor> cursor = _client.query(NamespaceString(ns), "", 0, 0, 0, 0, 200);
CursorId cursorId = cursor->getCursorId();
// Count 500 results, spanning a few batches of documents.
@@ -397,19 +397,19 @@ public:
}
void testLimit(int limit) {
- ASSERT_EQUALS(_client.query(ns, BSONObj(), limit)->itcount(), limit);
+ ASSERT_EQUALS(_client.query(NamespaceString(ns), BSONObj(), limit)->itcount(), limit);
}
void run() {
for (int i = 0; i < 1000; i++)
insert(ns, BSON(GENOID << "i" << i));
- ASSERT_EQUALS(_client.query(ns, BSONObj(), 1)->itcount(), 1);
- ASSERT_EQUALS(_client.query(ns, BSONObj(), 10)->itcount(), 10);
- ASSERT_EQUALS(_client.query(ns, BSONObj(), 101)->itcount(), 101);
- ASSERT_EQUALS(_client.query(ns, BSONObj(), 999)->itcount(), 999);
- ASSERT_EQUALS(_client.query(ns, BSONObj(), 1000)->itcount(), 1000);
- ASSERT_EQUALS(_client.query(ns, BSONObj(), 1001)->itcount(), 1000);
- ASSERT_EQUALS(_client.query(ns, BSONObj(), 0)->itcount(), 1000);
+ ASSERT_EQUALS(_client.query(NamespaceString(ns), BSONObj(), 1)->itcount(), 1);
+ ASSERT_EQUALS(_client.query(NamespaceString(ns), BSONObj(), 10)->itcount(), 10);
+ ASSERT_EQUALS(_client.query(NamespaceString(ns), BSONObj(), 101)->itcount(), 101);
+ ASSERT_EQUALS(_client.query(NamespaceString(ns), BSONObj(), 999)->itcount(), 999);
+ ASSERT_EQUALS(_client.query(NamespaceString(ns), BSONObj(), 1000)->itcount(), 1000);
+ ASSERT_EQUALS(_client.query(NamespaceString(ns), BSONObj(), 1001)->itcount(), 1000);
+ ASSERT_EQUALS(_client.query(NamespaceString(ns), BSONObj(), 0)->itcount(), 1000);
}
};
@@ -429,8 +429,12 @@ public:
insert(ns, BSON("a" << 0));
insert(ns, BSON("a" << 1));
insert(ns, BSON("a" << 2));
- unique_ptr<DBClientCursor> c = _client.query(
- ns, Query().hint(BSON("$natural" << 1)), 2, 0, 0, QueryOption_CursorTailable);
+ unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns),
+ Query().hint(BSON("$natural" << 1)),
+ 2,
+ 0,
+ 0,
+ QueryOption_CursorTailable);
ASSERT(0 != c->getCursorId());
while (c->more())
c->next();
@@ -457,13 +461,21 @@ public:
const char* ns = "unittests.querytests.EmptyTail";
_client.createCollection(ns, 1900, true);
- unique_ptr<DBClientCursor> c = _client.query(
- ns, Query().hint(BSON("$natural" << 1)), 2, 0, 0, QueryOption_CursorTailable);
+ unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns),
+ Query().hint(BSON("$natural" << 1)),
+ 2,
+ 0,
+ 0,
+ QueryOption_CursorTailable);
ASSERT_EQUALS(0, c->getCursorId());
ASSERT(c->isDead());
insert(ns, BSON("a" << 0));
- c = _client.query(
- ns, QUERY("a" << 1).hint(BSON("$natural" << 1)), 2, 0, 0, QueryOption_CursorTailable);
+ c = _client.query(NamespaceString(ns),
+ QUERY("a" << 1).hint(BSON("$natural" << 1)),
+ 2,
+ 0,
+ 0,
+ QueryOption_CursorTailable);
ASSERT(0 != c->getCursorId());
ASSERT(!c->isDead());
}
@@ -484,8 +496,12 @@ public:
_client.createCollection(ns, 8192, true, 2);
insert(ns, BSON("a" << 0));
insert(ns, BSON("a" << 1));
- unique_ptr<DBClientCursor> c = _client.query(
- ns, Query().hint(BSON("$natural" << 1)), 2, 0, 0, QueryOption_CursorTailable);
+ unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns),
+ Query().hint(BSON("$natural" << 1)),
+ 2,
+ 0,
+ 0,
+ QueryOption_CursorTailable);
c->next();
c->next();
ASSERT(!c->more());
@@ -512,8 +528,12 @@ public:
_client.createCollection(ns, 8192, true, 2);
insert(ns, BSON("a" << 0));
insert(ns, BSON("a" << 1));
- unique_ptr<DBClientCursor> c = _client.query(
- ns, Query().hint(BSON("$natural" << 1)), 2, 0, 0, QueryOption_CursorTailable);
+ unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns),
+ Query().hint(BSON("$natural" << 1)),
+ 2,
+ 0,
+ 0,
+ QueryOption_CursorTailable);
c->next();
c->next();
ASSERT(!c->more());
@@ -542,8 +562,12 @@ public:
_client.createCollection(ns, 1330, true);
insert(ns, BSON("a" << 0));
insert(ns, BSON("a" << 1));
- unique_ptr<DBClientCursor> c = _client.query(
- ns, Query().hint(BSON("$natural" << 1)), 2, 0, 0, QueryOption_CursorTailable);
+ unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns),
+ Query().hint(BSON("$natural" << 1)),
+ 2,
+ 0,
+ 0,
+ QueryOption_CursorTailable);
c->next();
c->next();
ASSERT(!c->more());
@@ -563,8 +587,9 @@ public:
void run() {
const char* ns = "unittests.querytests.TailCappedOnly";
_client.insert(ns, BSONObj());
- ASSERT_THROWS(_client.query(ns, BSONObj(), 0, 0, 0, QueryOption_CursorTailable),
- AssertionException);
+ ASSERT_THROWS(
+ _client.query(NamespaceString(ns), BSONObj(), 0, 0, 0, QueryOption_CursorTailable),
+ AssertionException);
}
};
@@ -602,12 +627,12 @@ public:
info);
insertA(ns, 0);
insertA(ns, 1);
- unique_ptr<DBClientCursor> c1 =
- _client.query(ns, QUERY("a" << GT << -1), 0, 0, 0, QueryOption_CursorTailable);
+ unique_ptr<DBClientCursor> c1 = _client.query(
+ NamespaceString(ns), QUERY("a" << GT << -1), 0, 0, 0, QueryOption_CursorTailable);
OID id;
id.init("000000000000000000000000");
- unique_ptr<DBClientCursor> c2 =
- _client.query(ns, QUERY("value" << GT << id), 0, 0, 0, QueryOption_CursorTailable);
+ unique_ptr<DBClientCursor> c2 = _client.query(
+ NamespaceString(ns), QUERY("value" << GT << id), 0, 0, 0, QueryOption_CursorTailable);
c1->next();
c1->next();
ASSERT(!c1->more());
@@ -646,7 +671,7 @@ public:
insert(ns, BSON("ts" << Timestamp(1000, 1)));
insert(ns, BSON("ts" << Timestamp(1000, 2)));
unique_ptr<DBClientCursor> c =
- _client.query(ns,
+ _client.query(NamespaceString(ns),
QUERY("ts" << GT << Timestamp(1000, 1)).hint(BSON("$natural" << 1)),
0,
0,
@@ -657,7 +682,7 @@ public:
ASSERT(!c->more());
insert(ns, BSON("ts" << Timestamp(1000, 3)));
- c = _client.query(ns,
+ c = _client.query(NamespaceString(ns),
QUERY("ts" << GT << Timestamp(1000, 1)).hint(BSON("$natural" << 1)),
0,
0,
@@ -690,7 +715,7 @@ public:
insert(ns, BSON("ts" << Timestamp(1000, 1)));
insert(ns, BSON("ts" << Timestamp(1000, 2)));
unique_ptr<DBClientCursor> c = _client.query(
- ns,
+ NamespaceString(ns),
QUERY("ts" << GT << Timestamp(1000, 1)).hint(BSON("$natural" << 1)).explain(),
0,
0,
@@ -906,7 +931,9 @@ public:
const char* ns = "unittests.querytests.Size";
_client.insert(ns, fromjson("{a:[1,2,3]}"));
ASSERT_OK(dbtests::createIndex(&_opCtx, ns, BSON("a" << 1)));
- ASSERT(_client.query(ns, QUERY("a" << mongo::BSIZE << 3).hint(BSON("a" << 1)))->more());
+ ASSERT(_client
+ .query(NamespaceString(ns), QUERY("a" << mongo::BSIZE << 3).hint(BSON("a" << 1)))
+ ->more());
}
};
@@ -918,10 +945,13 @@ public:
void run() {
const char* ns = "unittests.querytests.IndexedArray";
_client.insert(ns, fromjson("{a:[1,2,3]}"));
- ASSERT(_client.query(ns, Query("{a:[1,2,3]}"))->more());
+ ASSERT(_client.query(NamespaceString(ns), Query("{a:[1,2,3]}"))->more());
ASSERT_OK(dbtests::createIndex(&_opCtx, ns, BSON("a" << 1)));
- ASSERT(_client.query(ns, Query("{a:{$in:[1,[1,2,3]]}}").hint(BSON("a" << 1)))->more());
- ASSERT(_client.query(ns, Query("{a:[1,2,3]}").hint(BSON("a" << 1)))->more()); // SERVER-146
+ ASSERT(
+ _client.query(NamespaceString(ns), Query("{a:{$in:[1,[1,2,3]]}}").hint(BSON("a" << 1)))
+ ->more());
+ ASSERT(_client.query(NamespaceString(ns), Query("{a:[1,2,3]}").hint(BSON("a" << 1)))
+ ->more()); // SERVER-146
}
};
@@ -941,10 +971,14 @@ public:
private:
void check(const string& hintField) {
const char* ns = "unittests.querytests.InsideArray";
- ASSERT(_client.query(ns, Query("{a:[[1],2]}").hint(BSON(hintField << 1)))->more());
- ASSERT(_client.query(ns, Query("{a:[1]}").hint(BSON(hintField << 1)))->more());
- ASSERT(_client.query(ns, Query("{a:2}").hint(BSON(hintField << 1)))->more());
- ASSERT(!_client.query(ns, Query("{a:1}").hint(BSON(hintField << 1)))->more());
+ ASSERT(_client.query(NamespaceString(ns), Query("{a:[[1],2]}").hint(BSON(hintField << 1)))
+ ->more());
+ ASSERT(_client.query(NamespaceString(ns), Query("{a:[1]}").hint(BSON(hintField << 1)))
+ ->more());
+ ASSERT(
+ _client.query(NamespaceString(ns), Query("{a:2}").hint(BSON(hintField << 1)))->more());
+ ASSERT(
+ !_client.query(NamespaceString(ns), Query("{a:1}").hint(BSON(hintField << 1)))->more());
}
};
@@ -958,8 +992,10 @@ public:
_client.insert(ns, fromjson("{'_id':1,a:[1]}"));
_client.insert(ns, fromjson("{'_id':2,a:[[1]]}"));
ASSERT_OK(dbtests::createIndex(&_opCtx, ns, BSON("a" << 1)));
- ASSERT_EQUALS(
- 1, _client.query(ns, Query("{a:[1]}").hint(BSON("a" << 1)))->next().getIntField("_id"));
+ ASSERT_EQUALS(1,
+ _client.query(NamespaceString(ns), Query("{a:[1]}").hint(BSON("a" << 1)))
+ ->next()
+ .getIntField("_id"));
}
};
@@ -979,8 +1015,10 @@ public:
private:
void check(const string& hintField) {
const char* ns = "unittests.querytests.SubobjArr";
- ASSERT(_client.query(ns, Query("{'a.b':1}").hint(BSON(hintField << 1)))->more());
- ASSERT(_client.query(ns, Query("{'a.b':[1]}").hint(BSON(hintField << 1)))->more());
+ ASSERT(_client.query(NamespaceString(ns), Query("{'a.b':1}").hint(BSON(hintField << 1)))
+ ->more());
+ ASSERT(_client.query(NamespaceString(ns), Query("{'a.b':[1]}").hint(BSON(hintField << 1)))
+ ->more());
}
};
@@ -997,7 +1035,7 @@ public:
_client.insert(ns, BSON("a" << 2 << "b" << 1));
_client.insert(ns, BSON("a" << 2 << "b" << 2));
- ASSERT_EQUALS(4, count(_client.query(ns, BSONObj())));
+ ASSERT_EQUALS(4, count(_client.query(NamespaceString(ns), BSONObj())));
BSONObj hints[] = {BSONObj(), BSON("a" << 1 << "b" << 1)};
for (int i = 0; i < 2; ++i) {
check(0, 0, 3, 3, 4, hints[i]);
@@ -1022,7 +1060,7 @@ private:
q = q.minKey(BSON("a" << minA << "b" << minB)).maxKey(BSON("a" << maxA << "b" << maxB));
if (!hint.isEmpty())
q.hint(hint);
- return _client.query(ns, q);
+ return _client.query(NamespaceString(ns), q);
}
void check(
int minA, int minB, int maxA, int maxB, int expectedCount, const BSONObj& hint = empty_) {
@@ -1161,7 +1199,7 @@ public:
_client.dropCollection("unittests.querytests.DifferentNumbers");
}
void t(const char* ns) {
- unique_ptr<DBClientCursor> cursor = _client.query(ns, Query().sort("7"));
+ unique_ptr<DBClientCursor> cursor = _client.query(NamespaceString(ns), Query().sort("7"));
while (cursor->more()) {
BSONObj o = cursor->next();
verify(o.valid(BSONVersion::kLatest));
@@ -1307,7 +1345,7 @@ public:
int a = count();
unique_ptr<DBClientCursor> c =
- _client.query(ns(),
+ _client.query(NamespaceString(ns()),
QUERY("i" << GT << 0).hint(BSON("$natural" << 1)),
0,
0,
@@ -1469,13 +1507,14 @@ public:
for (int k = 0; k < 5; ++k) {
_client.insert(ns(), BSON("ts" << Timestamp(1000, i++)));
- unsigned min = _client.query(ns(), Query().sort(BSON("$natural" << 1)))
- ->next()["ts"]
- .timestamp()
- .getInc();
+ unsigned min =
+ _client.query(NamespaceString(ns()), Query().sort(BSON("$natural" << 1)))
+ ->next()["ts"]
+ .timestamp()
+ .getInc();
for (unsigned j = -1; j < i; ++j) {
unique_ptr<DBClientCursor> c =
- _client.query(ns(),
+ _client.query(NamespaceString(ns()),
QUERY("ts" << GTE << Timestamp(1000, j)),
0,
0,
@@ -1525,13 +1564,14 @@ public:
for (int k = 0; k < 5; ++k) {
_client.insert(ns(), BSON("ts" << Timestamp(1000, i++)));
- unsigned min = _client.query(ns(), Query().sort(BSON("$natural" << 1)))
- ->next()["ts"]
- .timestamp()
- .getInc();
+ unsigned min =
+ _client.query(NamespaceString(ns()), Query().sort(BSON("$natural" << 1)))
+ ->next()["ts"]
+ .timestamp()
+ .getInc();
for (unsigned j = -1; j < i; ++j) {
unique_ptr<DBClientCursor> c =
- _client.query(ns(),
+ _client.query(NamespaceString(ns()),
QUERY("ts" << GTE << Timestamp(1000, j)),
0,
0,
@@ -1569,8 +1609,12 @@ public:
size_t startNumCursors = numCursorsOpen();
// Check OplogReplay mode with missing collection.
- unique_ptr<DBClientCursor> c0 = _client.query(
- ns(), QUERY("ts" << GTE << Timestamp(1000, 50)), 0, 0, 0, QueryOption_OplogReplay);
+ unique_ptr<DBClientCursor> c0 = _client.query(NamespaceString(ns()),
+ QUERY("ts" << GTE << Timestamp(1000, 50)),
+ 0,
+ 0,
+ 0,
+ QueryOption_OplogReplay);
ASSERT(!c0->more());
BSONObj info;
@@ -1587,15 +1631,23 @@ public:
info));
// Check OplogReplay mode with empty collection.
- unique_ptr<DBClientCursor> c = _client.query(
- ns(), QUERY("ts" << GTE << Timestamp(1000, 50)), 0, 0, 0, QueryOption_OplogReplay);
+ unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns()),
+ QUERY("ts" << GTE << Timestamp(1000, 50)),
+ 0,
+ 0,
+ 0,
+ QueryOption_OplogReplay);
ASSERT(!c->more());
// Check with some docs in the collection.
for (int i = 100; i < 150; _client.insert(ns(), BSON("ts" << Timestamp(1000, i++))))
;
- c = _client.query(
- ns(), QUERY("ts" << GTE << Timestamp(1000, 50)), 0, 0, 0, QueryOption_OplogReplay);
+ c = _client.query(NamespaceString(ns()),
+ QUERY("ts" << GTE << Timestamp(1000, 50)),
+ 0,
+ 0,
+ 0,
+ QueryOption_OplogReplay);
ASSERT(c->more());
ASSERT_EQUALS(100u, c->next()["ts"].timestamp().getInc());
@@ -1673,7 +1725,7 @@ public:
{
// With five results and a batch size of 5, a cursor is created since we don't know
// there are no more results.
- std::unique_ptr<DBClientCursor> c = _client.query(ns(), Query(), 5);
+ std::unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns()), Query(), 5);
ASSERT(c->more());
ASSERT_NE(0, c->getCursorId());
for (int i = 0; i < 5; ++i) {
@@ -1685,7 +1737,7 @@ public:
{
// With a batchsize of 6 we know there are no more results so we don't create a
// cursor.
- std::unique_ptr<DBClientCursor> c = _client.query(ns(), Query(), 6);
+ std::unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns()), Query(), 6);
ASSERT(c->more());
ASSERT_EQ(0, c->getCursorId());
}
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index 5707b2f667f..662f6c8430e 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -186,7 +186,7 @@ protected:
check(o, one(o));
}
void checkAll(const BSONObj& o) const {
- unique_ptr<DBClientCursor> c = _client.query(ns(), o);
+ unique_ptr<DBClientCursor> c = _client.query(NamespaceString(ns()), o);
verify(c->more());
while (c->more()) {
check(o, c->next());
@@ -221,14 +221,14 @@ protected:
return count;
}
int opCount() {
- return DBDirectClient(&_opCtx).query(cllNS(), BSONObj())->itcount();
+ return DBDirectClient(&_opCtx).query(NamespaceString(cllNS()), BSONObj())->itcount();
}
void applyAllOperations() {
Lock::GlobalWrite lk(&_opCtx);
vector<BSONObj> ops;
{
DBDirectClient db(&_opCtx);
- auto cursor = db.query(cllNS(), BSONObj());
+ auto cursor = db.query(NamespaceString(cllNS()), BSONObj());
while (cursor->more()) {
ops.push_back(cursor->nextSafe());
}
@@ -762,7 +762,8 @@ class MultiInc : public Base {
public:
string s() const {
stringstream ss;
- unique_ptr<DBClientCursor> cc = _client.query(ns(), Query().sort(BSON("_id" << 1)));
+ unique_ptr<DBClientCursor> cc =
+ _client.query(NamespaceString(ns()), Query().sort(BSON("_id" << 1)));
bool first = true;
while (cc->more()) {
if (first)
diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp
index fa2a8ca8b2e..23b7b2f0208 100644
--- a/src/mongo/dbtests/updatetests.cpp
+++ b/src/mongo/dbtests/updatetests.cpp
@@ -438,7 +438,8 @@ class MultiInc : public SetBase {
public:
string s() {
stringstream ss;
- unique_ptr<DBClientCursor> cc = _client.query(ns(), Query().sort(BSON("_id" << 1)));
+ unique_ptr<DBClientCursor> cc =
+ _client.query(NamespaceString(ns()), Query().sort(BSON("_id" << 1)));
bool first = true;
while (cc->more()) {
if (first)
diff --git a/src/mongo/s/client/parallel.cpp b/src/mongo/s/client/parallel.cpp
index e291f37a80d..a9f2c60eee7 100644
--- a/src/mongo/s/client/parallel.cpp
+++ b/src/mongo/s/client/parallel.cpp
@@ -546,7 +546,7 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
state->cursor.reset(new DBClientCursor(
state->conn->get(),
- ns,
+ NamespaceString(ns),
_qSpec.query(),
isCommand() ? 1 : 0, // nToReturn (0 if query indicates multi)
0, // nToSkip
@@ -573,7 +573,7 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
state->cursor.reset(new DBClientCursor(
state->conn->get(),
- ns,
+ NamespaceString(ns),
_qSpec.query(),
_qSpec.ntoreturn(), // nToReturn
_qSpec.ntoskip(), // nToSkip
@@ -1002,7 +1002,7 @@ void ParallelSortClusteredCursor::_oldInit() {
if (!_cursors[i].get())
_cursors[i].reset(
new DBClientCursor(conns[i]->get(),
- _ns,
+ NamespaceString(_ns),
_query,
0, // nToReturn
0, // nToSkip
diff --git a/src/mongo/s/client/rs_local_client.cpp b/src/mongo/s/client/rs_local_client.cpp
index 21888c8fc1c..0b7d5079ea5 100644
--- a/src/mongo/s/client/rs_local_client.cpp
+++ b/src/mongo/s/client/rs_local_client.cpp
@@ -135,7 +135,7 @@ StatusWith<Shard::QueryResponse> RSLocalClient::queryOnce(
try {
std::unique_ptr<DBClientCursor> cursor =
- client.query(nss.ns().c_str(), fullQuery, limit.get_value_or(0));
+ client.query(nss, fullQuery, limit.get_value_or(0));
if (!cursor) {
return {ErrorCodes::OperationFailed,
diff --git a/src/mongo/s/client/shard_connection_test.cpp b/src/mongo/s/client/shard_connection_test.cpp
index fd3d9dd9a14..1fa07c1dc2f 100644
--- a/src/mongo/s/client/shard_connection_test.cpp
+++ b/src/mongo/s/client/shard_connection_test.cpp
@@ -168,7 +168,7 @@ TEST_F(ShardConnFixture, InvalidateBadConnInPool) {
killServer();
try {
- conn2.get()->query("test.user", mongo::Query());
+ conn2.get()->query(NamespaceString("test.user"), mongo::Query());
} catch (const mongo::NetworkException&) {
}
@@ -187,7 +187,7 @@ TEST_F(ShardConnFixture, DontReturnKnownBadConnToPool) {
killServer();
try {
- conn3.get()->query("test.user", mongo::Query());
+ conn3.get()->query(NamespaceString("test.user"), mongo::Query());
} catch (const mongo::NetworkException&) {
}
@@ -210,7 +210,7 @@ TEST_F(ShardConnFixture, BadConnClearsPoolWhenKilled) {
killServer();
try {
- conn3.get()->query("test.user", mongo::Query());
+ conn3.get()->query(NamespaceString("test.user"), mongo::Query());
} catch (const mongo::NetworkException&) {
}
@@ -263,7 +263,7 @@ TEST_F(ShardConnFixture, InvalidateBadConnEvenWhenPoolIsFull) {
killServer();
try {
- conn2.get()->query("test.user", mongo::Query());
+ conn2.get()->query(NamespaceString("test.user"), mongo::Query());
} catch (const mongo::NetworkException&) {
}
diff --git a/src/mongo/scripting/engine.cpp b/src/mongo/scripting/engine.cpp
index 57a5d98f1e6..996225e5fbe 100644
--- a/src/mongo/scripting/engine.cpp
+++ b/src/mongo/scripting/engine.cpp
@@ -215,7 +215,7 @@ void Scope::loadStored(OperationContext* opCtx, bool ignoreNotConnected) {
return;
_loadedVersion = lastVersion;
- string coll = _localDBName + ".system.js";
+ NamespaceString coll(_localDBName, "system.js");
auto directDBClient = DBDirectClientFactory::get(opCtx).create(opCtx);
diff --git a/src/mongo/scripting/mozjs/mongo.cpp b/src/mongo/scripting/mozjs/mongo.cpp
index 0b88d21fb60..14a9cc8972a 100644
--- a/src/mongo/scripting/mozjs/mongo.cpp
+++ b/src/mongo/scripting/mozjs/mongo.cpp
@@ -291,8 +291,13 @@ void MongoBase::Functions::find::call(JSContext* cx, JS::CallArgs args) {
// The shell only calls this method when it wants to test OP_QUERY.
options |= DBClientCursor::QueryOptionLocal_forceOpQuery;
- std::unique_ptr<DBClientCursor> cursor(
- conn->query(ns, q, nToReturn, nToSkip, haveFields ? &fields : NULL, options, batchSize));
+ std::unique_ptr<DBClientCursor> cursor(conn->query(NamespaceString(ns),
+ q,
+ nToReturn,
+ nToSkip,
+ haveFields ? &fields : NULL,
+ options,
+ batchSize));
if (!cursor.get()) {
uasserted(ErrorCodes::InternalError, "error doing query: failed");
}
@@ -490,7 +495,7 @@ void MongoBase::Functions::cursorFromId::call(JSContext* cx, JS::CallArgs args)
// The shell only calls this method when it wants to test OP_GETMORE.
auto cursor = stdx::make_unique<DBClientCursor>(
- conn, ns, cursorId, 0, DBClientCursor::QueryOptionLocal_forceOpQuery);
+ conn, NamespaceString(ns), cursorId, 0, DBClientCursor::QueryOptionLocal_forceOpQuery);
if (args.get(2).isNumber())
cursor->setBatchSize(ValueWriter(cx, args.get(2)).toInt32());
diff --git a/src/mongo/shell/bench.cpp b/src/mongo/shell/bench.cpp
index 728c0abd94d..197cbf336dd 100644
--- a/src/mongo/shell/bench.cpp
+++ b/src/mongo/shell/bench.cpp
@@ -1108,14 +1108,14 @@ void BenchRunOp::executeOnce(DBClientBase* conn,
stdx::function<void(const BSONObj&)> castedDoNothing(doNothing);
count =
conn->query(castedDoNothing,
- this->ns,
+ NamespaceString(this->ns),
fixedQuery,
&this->projection,
this->options | DBClientCursor::QueryOptionLocal_forceOpQuery);
} else {
BenchRunEventTrace _bret(&state->stats->queryCounter);
std::unique_ptr<DBClientCursor> cursor(
- conn->query(this->ns,
+ conn->query(NamespaceString(this->ns),
fixedQuery,
this->limit,
this->skip,