summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document.h
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2013-12-13 13:39:01 -0500
committerMathias Stearn <mathias@10gen.com>2013-12-18 19:09:17 -0500
commit170e563e4cfa069f2128379e7b997e6777e0ee99 (patch)
treed4cbc8451e1ee33b120004a867bfcb25bfdca62d /src/mongo/db/pipeline/document.h
parent3e707bcd22b7c0e8275d25bf8e8b28c3cec4cc67 (diff)
downloadmongo-170e563e4cfa069f2128379e7b997e6777e0ee99.tar.gz
SERVER-11675 Agg text support
To enable this, Documents now can store "metadata" that gets carried though the pipeline as long as the result is the same logical document. This includes crossing the shard-to-merger boundary.
Diffstat (limited to 'src/mongo/db/pipeline/document.h')
-rw-r--r--src/mongo/db/pipeline/document.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/document.h b/src/mongo/db/pipeline/document.h
index 7bb79e68db8..7f2fde8a26f 100644
--- a/src/mongo/db/pipeline/document.h
+++ b/src/mongo/db/pipeline/document.h
@@ -115,6 +115,8 @@ namespace mongo {
* as strings are compared, but comparing one field at a time instead
* of one character at a time.
*
+ * Note: This does not consider metadata when comparing documents.
+ *
* @returns an integer less than zero, zero, or an integer greater than
* zero, depending on whether lhs < rhs, lhs == rhs, or lhs > rhs
* Warning: may return values other than -1, 0, or 1
@@ -133,10 +135,26 @@ namespace mongo {
*/
void hash_combine(size_t &seed) const;
- /// Add this document to the BSONObj under construction with the given BSONObjBuilder.
+ /**
+ * Add this document to the BSONObj under construction with the given BSONObjBuilder.
+ * Does not include metadata.
+ */
void toBson(BSONObjBuilder *pBsonObjBuilder) const;
BSONObj toBson() const;
+ /**
+ * Like toBson, but includes metadata at the top-level.
+ * Output is parseable by fromBsonWithMetaData
+ */
+ BSONObj toBsonWithMetaData() const;
+
+ /**
+ * Like Document(BSONObj) but treats top-level fields with special names as metadata.
+ * Special field names are available as static constants on this class with names starting
+ * with metaField.
+ */
+ static Document fromBsonWithMetaData(const BSONObj& bson);
+
// Support BSONObjBuilder and BSONArrayBuilder "stream" API
friend BSONObjBuilder& operator << (BSONObjBuilderValueStream& builder, const Document& d);
@@ -155,6 +173,10 @@ namespace mongo {
*/
Document clone() const { return Document(storage().clone().get()); }
+ static const StringData metaFieldTextScore; // "$textScore"
+ bool hasTextScore() const { return storage().hasTextScore(); }
+ double getTextScore() const { return storage().getTextScore(); }
+
/// members for Sorter
struct SorterDeserializeSettings {}; // unused
void serializeForSorter(BufBuilder& buf) const;
@@ -339,6 +361,16 @@ namespace mongo {
getNestedField(positions) = val;
}
+ /**
+ * Copies all metadata from source if it has any.
+ * Note: does not clear metadata from this.
+ */
+ void copyMetaDataFrom(const Document& source) {
+ storage().copyMetaDataFrom(source.storage());
+ }
+
+ void setTextScore(double score) { storage().setTextScore(score); }
+
/** Convert to a read-only document and release reference.
*
* Call this to indicate that you are done with this Document and will