diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2016-02-04 18:26:04 -0500 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2016-02-04 18:26:04 -0500 |
commit | 66cd4ef95f4d5458678fcb772057e95b4ad5a26f (patch) | |
tree | de13a578b268c012980e7751dcff324e7deec692 /src/mongo/db | |
parent | e50ae3193457da843f9bca825eb695207070ae3a (diff) | |
download | mongo-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')
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 6 |
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); |