summaryrefslogtreecommitdiff
path: root/src/mongo/bson/util
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2014-08-04 06:13:43 -0400
committermatt dannenberg <matt.dannenberg@10gen.com>2014-08-05 04:54:29 -0400
commit796797ddf9bb6355bc7e2ffef52c7baaf9398c4c (patch)
tree627e1fdf0610c2d0c6f24d607aae766b761c9e1a /src/mongo/bson/util
parent87fbf90ba0096550a32f6f9967f5daa44398e8c6 (diff)
downloadmongo-796797ddf9bb6355bc7e2ffef52c7baaf9398c4c.tar.gz
SERVER-14616 replace BSONObj with UpdatePositionArgs
Diffstat (limited to 'src/mongo/bson/util')
-rw-r--r--src/mongo/bson/util/bson_extract.cpp22
-rw-r--r--src/mongo/bson/util/bson_extract.h27
2 files changed, 49 insertions, 0 deletions
diff --git a/src/mongo/bson/util/bson_extract.cpp b/src/mongo/bson/util/bson_extract.cpp
index 09d269eb373..9c1cb45c6b7 100644
--- a/src/mongo/bson/util/bson_extract.cpp
+++ b/src/mongo/bson/util/bson_extract.cpp
@@ -106,6 +106,28 @@ namespace mongo {
return Status::OK();
}
+ Status bsonExtractOpTimeField(const BSONObj& object,
+ const StringData& fieldName,
+ OpTime* out) {
+ BSONElement element;
+ Status status = bsonExtractTypedField(object, fieldName, Timestamp, &element);
+ if (!status.isOK())
+ return status;
+ *out = element._opTime();
+ return Status::OK();
+ }
+
+ Status bsonExtractOIDField(const BSONObj& object,
+ const StringData& fieldName,
+ OID* out) {
+ BSONElement element;
+ Status status = bsonExtractTypedField(object, fieldName, jstOID, &element);
+ if (!status.isOK())
+ return status;
+ *out = element.OID();
+ return Status::OK();
+ }
+
Status bsonExtractStringFieldWithDefault(const BSONObj& object,
const StringData& fieldName,
const StringData& defaultValue,
diff --git a/src/mongo/bson/util/bson_extract.h b/src/mongo/bson/util/bson_extract.h
index eb047e8ffb6..dde7be26027 100644
--- a/src/mongo/bson/util/bson_extract.h
+++ b/src/mongo/bson/util/bson_extract.h
@@ -28,6 +28,7 @@
#pragma once
#include <string>
+#include <vector>
#include "mongo/base/status.h"
#include "mongo/base/string_data.h"
@@ -37,6 +38,8 @@ namespace mongo {
class BSONObj;
class BSONElement;
+ class OID;
+ class OpTime;
/**
* Finds an element named "fieldName" in "object".
@@ -100,6 +103,30 @@ namespace mongo {
std::string* out);
/**
+ * Finds an OpTime-typed element named "fieldName" in "object" and stores its value in "out".
+ *
+ * Returns Status::OK() and sets *out to the found element's OpTime value on success. Returns
+ * ErrorCodes::NoSuchKey if there are no matches for "fieldName", and ErrorCodes::TypeMismatch
+ * if the type of the matching element is not OpTime. For return values other than
+ * Status::OK(), the resulting value of "*out" is undefined.
+ */
+ Status bsonExtractOpTimeField(const BSONObj& object,
+ const StringData& fieldName,
+ OpTime* out);
+
+ /**
+ * Finds an OID-typed element named "fieldName" in "object" and stores its value in "out".
+ *
+ * Returns Status::OK() and sets *out to the found element's OID value on success. Returns
+ * ErrorCodes::NoSuchKey if there are no matches for "fieldName", and ErrorCodes::TypeMismatch
+ * if the type of the matching element is not OID. For return values other than Status::OK(),
+ * the resulting value of "*out" is undefined.
+ */
+ Status bsonExtractOIDField(const BSONObj& object,
+ const StringData& fieldName,
+ OID* out);
+
+ /**
* Finds a bool-like element named "fieldName" in "object".
*
* If a field named "fieldName" is present, and is either a number or boolean type, stores the