summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/create_indexes.cpp
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2016-02-04 18:26:04 -0500
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2016-02-04 18:26:04 -0500
commit66cd4ef95f4d5458678fcb772057e95b4ad5a26f (patch)
treede13a578b268c012980e7751dcff324e7deec692 /src/mongo/db/commands/create_indexes.cpp
parente50ae3193457da843f9bca825eb695207070ae3a (diff)
downloadmongo-66cd4ef95f4d5458678fcb772057e95b4ad5a26f.tar.gz
SERVER-12747 Add field to command result _after_ collection is created.
It's possible for Database::createCollection() to throw an exception after the "createdCollectionAutomatically" field has been added to the BSONObjBuilder& result object in the "createIndexes" command.
Diffstat (limited to 'src/mongo/db/commands/create_indexes.cpp')
-rw-r--r--src/mongo/db/commands/create_indexes.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index f9823559e4b..bf560e1cb8d 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -174,8 +174,9 @@ public:
}
Collection* collection = db->getCollection(ns.ns());
- result.appendBool("createdCollectionAutomatically", collection == NULL);
- if (!collection) {
+ if (collection) {
+ result.appendBool("createdCollectionAutomatically", false);
+ } else {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
WriteUnitOfWork wunit(txn);
collection = db->createCollection(txn, ns.ns(), CollectionOptions());
@@ -183,6 +184,7 @@ public:
wunit.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "createIndexes", ns.ns());
+ result.appendBool("createdCollectionAutomatically", true);
}
const int numIndexesBefore = collection->getIndexCatalog()->numIndexesTotal(txn);