diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-11-14 14:13:03 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-11-15 10:08:45 -0500 |
commit | 21821549cdeef84173293c46725695fc3a7834b0 (patch) | |
tree | a6d68779f04e83e289d036418d20087522e09d1b /src/mongo/bson/util | |
parent | 19449d2883f2a97b622102935a63606d950573ad (diff) | |
download | mongo-21821549cdeef84173293c46725695fc3a7834b0.tar.gz |
SERVER-26927 Rename maxStalenessMS to maxStalenessSeconds and support doubles
Diffstat (limited to 'src/mongo/bson/util')
-rw-r--r-- | src/mongo/bson/util/bson_extract.cpp | 15 | ||||
-rw-r--r-- | src/mongo/bson/util/bson_extract.h | 12 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/mongo/bson/util/bson_extract.cpp b/src/mongo/bson/util/bson_extract.cpp index b3ff37ca1b2..84c9cc92de6 100644 --- a/src/mongo/bson/util/bson_extract.cpp +++ b/src/mongo/bson/util/bson_extract.cpp @@ -170,6 +170,21 @@ Status bsonExtractIntegerField(const BSONObj& object, StringData fieldName, long return Status::OK(); } +Status bsonExtractDoubleField(const BSONObj& object, StringData fieldName, double* out) { + BSONElement value; + Status status = bsonExtractField(object, fieldName, &value); + if (!status.isOK()) + return status; + if (!value.isNumber()) { + return Status(ErrorCodes::TypeMismatch, + mongoutils::str::stream() << "Expected field \"" << fieldName + << "\" to have numeric type, but found " + << typeName(value.type())); + } + *out = value.numberDouble(); + return Status::OK(); +} + Status bsonExtractIntegerFieldWithDefault(const BSONObj& object, StringData fieldName, long long defaultValue, diff --git a/src/mongo/bson/util/bson_extract.h b/src/mongo/bson/util/bson_extract.h index a2189a4d57b..cedc84cd01f 100644 --- a/src/mongo/bson/util/bson_extract.h +++ b/src/mongo/bson/util/bson_extract.h @@ -86,6 +86,18 @@ Status bsonExtractBooleanField(const BSONObj& object, StringData fieldName, bool Status bsonExtractIntegerField(const BSONObj& object, StringData fieldName, long long* out); /** + * Finds an element named "fieldName" in "object" that represents a double-precision floating point + * value. + * + * Returns Status::OK() and sets *out to the element's double floating point value representation on + * success. Returns ErrorCodes::NoSuchKey if there are no matches for "fieldName". Returns + * ErrorCodes::TypeMismatch if the value of the matching element is not of a numeric type. Returns + * ErrorCodes::BadValue if the value does not have an exact floating point number representation. + * For return values other than Status::OK(), the resulting value of "*out" is undefined. + */ +Status bsonExtractDoubleField(const BSONObj& object, StringData fieldName, double* out); + +/** * Finds a string-typed element named "fieldName" in "object" and stores its value in "out". * * Returns Status::OK() and sets *out to the found element's std::string value on success. Returns |