summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/index_catalog.cpp
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2015-05-06 16:17:22 -0400
committerJason Rassi <rassi@10gen.com>2015-05-06 23:38:15 -0400
commitc5c476f6a5f3376fbf18b3f24fc450bd34aaff10 (patch)
tree31e71c7cab645bc4c88d833399cafeae024ac8f2 /src/mongo/db/catalog/index_catalog.cpp
parentd2ab9818beee1416c18e8cae818bc392f94d440f (diff)
downloadmongo-c5c476f6a5f3376fbf18b3f24fc450bd34aaff10.tar.gz
SERVER-18170 Forbid creation of _id index if it's also a partial index
Diffstat (limited to 'src/mongo/db/catalog/index_catalog.cpp')
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index 65836ebaeda..c1ce3e8fae4 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -561,25 +561,12 @@ namespace {
<< keyStatus.reason() );
}
- if ( IndexDescriptor::isIdIndexPattern( key ) ) {
- BSONElement uniqueElt = spec["unique"];
- if ( !uniqueElt.eoo() && !uniqueElt.trueValue() ) {
- return Status( ErrorCodes::CannotCreateIndex, "_id index cannot be non-unique" );
- }
- }
- else {
- // for non _id indexes, we check to see if replication has turned off all indexes
- // we _always_ created _id index
- if (!repl::getGlobalReplicationCoordinator()->buildsIndexes()) {
- // this is not exactly the right error code, but I think will make the most sense
- return Status( ErrorCodes::IndexAlreadyExists, "no indexes per repl" );
- }
- }
+ const bool isSparse = spec["sparse"].trueValue();
// Ensure if there is a filter, its valid.
BSONElement filterElement = spec.getField("filter");
- if ( filterElement.type() ) {
- if ( spec["sparse"].trueValue() ) {
+ if ( filterElement ) {
+ if ( isSparse ) {
return Status( ErrorCodes::CannotCreateIndex,
"cannot mix \"filter\" and \"sparse\" options" );
}
@@ -600,6 +587,25 @@ namespace {
}
}
+ if ( IndexDescriptor::isIdIndexPattern( key ) ) {
+ BSONElement uniqueElt = spec["unique"];
+ if ( uniqueElt && !uniqueElt.trueValue() ) {
+ return Status( ErrorCodes::CannotCreateIndex, "_id index cannot be non-unique" );
+ }
+
+ if ( filterElement ) {
+ return Status( ErrorCodes::CannotCreateIndex, "_id index cannot be partial" );
+ }
+ }
+ else {
+ // for non _id indexes, we check to see if replication has turned off all indexes
+ // we _always_ created _id index
+ if (!repl::getGlobalReplicationCoordinator()->buildsIndexes()) {
+ // this is not exactly the right error code, but I think will make the most sense
+ return Status( ErrorCodes::IndexAlreadyExists, "no indexes per repl" );
+ }
+ }
+
// --- only storage engine checks allowed below this ----
BSONElement storageEngineElement = spec.getField("storageEngine");