summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/client/dbclientcursor.cpp15
-rw-r--r--src/mongo/client/dbclientcursor.h10
-rw-r--r--src/mongo/db/commands/user_management_commands.cpp22
3 files changed, 32 insertions, 15 deletions
diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp
index 0efe1e2a32c..2736023861a 100644
--- a/src/mongo/client/dbclientcursor.cpp
+++ b/src/mongo/client/dbclientcursor.cpp
@@ -466,13 +466,15 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
nToSkip,
fieldsToReturn,
queryOptions,
- batchSize) {}
+ batchSize,
+ {}) {}
DBClientCursor::DBClientCursor(DBClientBase* client,
const std::string& ns,
long long cursorId,
int nToReturn,
- int queryOptions)
+ int queryOptions,
+ std::vector<BSONObj> initialBatch)
: DBClientCursor(client,
ns,
BSONObj(), // query
@@ -481,7 +483,8 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
0, // nToSkip
nullptr, // fieldsToReturn
queryOptions,
- 0) {} // batchSize
+ 0,
+ std::move(initialBatch)) {} // batchSize
DBClientCursor::DBClientCursor(DBClientBase* client,
const std::string& ns,
@@ -491,8 +494,10 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
int nToSkip,
const BSONObj* fieldsToReturn,
int queryOptions,
- int batchSize)
- : _client(client),
+ int batchSize,
+ std::vector<BSONObj> initialBatch)
+ : batch{std::move(initialBatch)},
+ _client(client),
_originalHost(_client->getServerAddress()),
ns(ns),
_isCommand(nsIsFull(ns) ? nsToCollectionSubstring(ns) == "$cmd" : false),
diff --git a/src/mongo/client/dbclientcursor.h b/src/mongo/client/dbclientcursor.h
index 0601a3bf6ef..876d3f30db7 100644
--- a/src/mongo/client/dbclientcursor.h
+++ b/src/mongo/client/dbclientcursor.h
@@ -152,7 +152,8 @@ public:
const std::string& ns,
long long cursorId,
int nToReturn,
- int options);
+ int options,
+ std::vector<BSONObj> initialBatch = {});
virtual ~DBClientCursor();
@@ -224,11 +225,16 @@ private:
int nToSkip,
const BSONObj* fieldsToReturn,
int queryOptions,
- int bs);
+ int bs,
+ std::vector<BSONObj> initialBatch);
int nextBatchSize();
struct Batch {
+ // TODO remove constructors after c++17 toolchain upgrade
+ Batch() = default;
+ Batch(std::vector<BSONObj> initial, size_t initialPos = 0)
+ : objs(std::move(initial)), pos(initialPos) {}
std::vector<BSONObj> objs;
size_t pos = 0;
};
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp
index 328fa7cb385..6d16c03c2a0 100644
--- a/src/mongo/db/commands/user_management_commands.cpp
+++ b/src/mongo/db/commands/user_management_commands.cpp
@@ -1370,21 +1370,27 @@ public:
pipeline.push_back(BSON("$match" << *args.filter));
}
+ DBDirectClient client(opCtx);
+
BSONObjBuilder responseBuilder;
AggregationRequest aggRequest(AuthorizationManager::usersCollectionNamespace,
std::move(pipeline));
- Status status = runAggregate(opCtx,
+ uassertStatusOK(runAggregate(opCtx,
AuthorizationManager::usersCollectionNamespace,
aggRequest,
aggRequest.serializeToCommandObj().toBson(),
- responseBuilder);
- uassertStatusOK(status);
-
+ responseBuilder));
CommandHelpers::appendSimpleCommandStatus(responseBuilder, true);
- auto swResponse = CursorResponse::parseFromBSON(responseBuilder.obj());
- uassertStatusOK(swResponse.getStatus());
- for (const BSONObj& obj : swResponse.getValue().getBatch()) {
- usersArrayBuilder.append(obj);
+ auto response = CursorResponse::parseFromBSONThrowing(responseBuilder.obj());
+ DBClientCursor cursor(&client,
+ response.getNSS().toString(),
+ response.getCursorId(),
+ 0,
+ 0,
+ response.releaseBatch());
+
+ while (cursor.more()) {
+ usersArrayBuilder.append(cursor.next());
}
}
result.append("users", usersArrayBuilder.arr());