From 78052771af75f9c6fdff10796c82a38167274a6f Mon Sep 17 00:00:00 2001 From: Geert Bosch Date: Thu, 2 Mar 2017 14:07:32 -0500 Subject: SERVER-27987 Create and persist UUIDs for newly created collections --- src/mongo/bson/bsonelement.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/mongo/bson/bsonelement.h') diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h index 111cbad442f..3120907b589 100644 --- a/src/mongo/bson/bsonelement.h +++ b/src/mongo/bson/bsonelement.h @@ -579,6 +579,17 @@ public: return Timestamp(); } + const std::array uuid() const { + int len = 0; + const char* data = nullptr; + if (type() == BinData && binDataType() == BinDataType::newUUID) + data = binData(len); + uassert(00000, "uuid must be a 16-byte binary field with UUID (4) subtype", len == 16); + std::array result; + memcpy(&result, data, len); + return result; + } + Date_t timestampTime() const { unsigned long long t = ConstDataView(value() + 4).read>(); return Date_t::fromMillisSinceEpoch(t * 1000); -- cgit v1.2.1