summaryrefslogtreecommitdiff
path: root/src/mongo/s/write_ops/batched_command_request.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/write_ops/batched_command_request.cpp')
-rw-r--r--src/mongo/s/write_ops/batched_command_request.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/mongo/s/write_ops/batched_command_request.cpp b/src/mongo/s/write_ops/batched_command_request.cpp
index 65bdf090ce0..322efc25afd 100644
--- a/src/mongo/s/write_ops/batched_command_request.cpp
+++ b/src/mongo/s/write_ops/batched_command_request.cpp
@@ -86,19 +86,41 @@ BatchedDeleteRequest* BatchedCommandRequest::getDeleteRequest() const {
bool BatchedCommandRequest::isInsertIndexRequest() const {
if (_batchType != BatchedCommandRequest::BatchType_Insert)
return false;
-
return getNS().isSystemDotIndexes();
}
-NamespaceString BatchedCommandRequest::getTargetingNSS() const {
- if (!isInsertIndexRequest()) {
- return getNS();
+bool BatchedCommandRequest::isValidIndexRequest(std::string* errMsg) const {
+ std::string dummy;
+ if (!errMsg)
+ errMsg = &dummy;
+ dassert(isInsertIndexRequest());
+
+ if (sizeWriteOps() != 1) {
+ *errMsg = "invalid batch request for index creation";
+ return false;
+ }
+
+ const NamespaceString& targetNSS = getTargetingNSS();
+ if (!targetNSS.isValid()) {
+ *errMsg = targetNSS.ns() + " is not a valid namespace to index";
+ return false;
}
- const auto& documents = _insertReq->getDocuments();
- invariant(documents.size() == 1);
+ const NamespaceString& reqNSS = getNS();
+ if (reqNSS.db().compare(targetNSS.db()) != 0) {
+ *errMsg =
+ targetNSS.ns() + " namespace is not in the request database " + reqNSS.db().toString();
+ return false;
+ }
+
+ return true;
+}
+
+const NamespaceString& BatchedCommandRequest::getTargetingNSS() const {
+ if (!isInsertIndexRequest())
+ return getNS();
- return NamespaceString(documents.at(0)["ns"].str());
+ return _insertReq->getIndexTargetingNS();
}
bool BatchedCommandRequest::isVerboseWC() const {