diff options
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 3da676da060..8dd89b032dd 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -165,25 +165,30 @@ bool Helpers::findById(OperationContext* opCtx, const IndexCatalog* catalog = collection->getIndexCatalog(); const IndexDescriptor* desc = catalog->findIdIndex(opCtx); - if (!desc && !clustered_util::isClusteredOnId(collection->getClusteredInfo())) { + if (!desc) { + if (clustered_util::isClusteredOnId(collection->getClusteredInfo())) { + if (indexFound) { + // A collection clustered on _id implicitly has an _id index but no explicit + // IndexDescriptor tied to it. + *indexFound = 1; + } + + Snapshotted<BSONObj> doc; + if (collection->findDoc(opCtx, + record_id_helpers::keyForObj(IndexBoundsBuilder::objFromElement( + query["_id"], collection->getDefaultCollator())), + &doc)) { + result = std::move(doc.value()); + return true; + } + } + return false; } if (indexFound) *indexFound = 1; - if (collection->isClustered()) { - Snapshotted<BSONObj> doc; - if (collection->findDoc(opCtx, - record_id_helpers::keyForObj(IndexBoundsBuilder::objFromElement( - query["_id"], collection->getDefaultCollator())), - &doc)) { - result = std::move(doc.value()); - return true; - } - return false; - } - auto recordId = catalog->getEntry(desc)->accessMethod()->asSortedData()->findSingle( opCtx, collection, query["_id"].wrap()); if (recordId.isNull()) |