summaryrefslogtreecommitdiff
path: root/src/mongo/bson/util
diff options
context:
space:
mode:
authorSpencer Jackson <spencer.jackson@mongodb.com>2016-09-26 12:53:47 -0400
committerSpencer Jackson <spencer.jackson@mongodb.com>2016-09-26 14:10:50 -0400
commit160a15c25fc59a74cc66cd593d0381741630776f (patch)
treedc6f623bbc248863a8fdf33f0c5dffc6ac96d0d4 /src/mongo/bson/util
parent27b2b2c926ff43f3111adef5a99537260a1b44ef (diff)
downloadmongo-160a15c25fc59a74cc66cd593d0381741630776f.tar.gz
SERVER-25994: Make applyOps check for specific permissions
Diffstat (limited to 'src/mongo/bson/util')
-rw-r--r--src/mongo/bson/util/bson_check.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/bson/util/bson_check.h b/src/mongo/bson/util/bson_check.h
index dd4f59816ba..e6f2e3c98bc 100644
--- a/src/mongo/bson/util/bson_check.h
+++ b/src/mongo/bson/util/bson_check.h
@@ -82,4 +82,18 @@ Status bsonCheckOnlyHasFields(StringData objectName,
return bsonCheckOnlyHasFields(objectName, o, &legals[0], legals + N);
}
+/**
+ * Throws a uassert if the type of the elem does not match that provided in expectedType
+ */
+inline void checkBSONType(BSONType expectedType, const BSONElement& elem) {
+ uassert(elem.type() == BSONType::EOO ? ErrorCodes::NoSuchKey : ErrorCodes::TypeMismatch,
+ str::stream() << "Wrong type for '" << elem.fieldNameStringData() << "'. Expected a "
+ << typeName(expectedType)
+ << ", got a "
+ << typeName(elem.type())
+ << '.',
+ elem.type() == expectedType);
+}
+
+
} // namespace mongo