summaryrefslogtreecommitdiff
path: root/src/mongo/db/field_ref.h
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@gmail.com>2018-09-21 04:12:00 +0100
committerBernard Gorman <bernard.gorman@gmail.com>2018-09-22 01:09:31 +0100
commit10a0d12e9ea977660eb247143b09ecfdc51d05ea (patch)
treeb7cacf5ae9fc8d81f1905cdf4969ce57fb167c1b /src/mongo/db/field_ref.h
parenta8995601144d16fe6c762624f64f5690b5caf684 (diff)
downloadmongo-10a0d12e9ea977660eb247143b09ecfdc51d05ea.tar.gz
SERVER-35493 Planning support for "field name or array index" path components in wildcard indexes
Diffstat (limited to 'src/mongo/db/field_ref.h')
-rw-r--r--src/mongo/db/field_ref.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/db/field_ref.h b/src/mongo/db/field_ref.h
index ad354a0f39c..96368b8f547 100644
--- a/src/mongo/db/field_ref.h
+++ b/src/mongo/db/field_ref.h
@@ -30,6 +30,7 @@
#include <boost/optional.hpp>
#include <iosfwd>
+#include <set>
#include <string>
#include <vector>
@@ -50,6 +51,12 @@ namespace mongo {
*/
class FieldRef {
public:
+ /**
+ * Returns true if the argument is a numeric string which is eligible to act as the key name for
+ * an element in a BSON array; in other words, the string matches the regex ^(0|[1-9]+[0-9]*)$.
+ */
+ static bool isNumericPathComponent(StringData component);
+
FieldRef() = default;
explicit FieldRef(StringData path);
@@ -94,11 +101,33 @@ public:
bool isPrefixOf(const FieldRef& other) const;
/**
+ * Returns true if 'this' FieldRef is a prefix of 'other', or if both paths are identical.
+ */
+ bool isPrefixOfOrEqualTo(const FieldRef& other) const;
+
+ /**
* Returns the number of field parts in the prefix that 'this' and 'other' share.
*/
size_t commonPrefixSize(const FieldRef& other) const;
/**
+ * Returns true if the specified path component is a numeric string which is eligible to act as
+ * the key name for an element in a BSON array; in other words, the fieldname matches the regex
+ * ^(0|[1-9]+[0-9]*)$.
+ */
+ bool isNumericPathComponent(size_t i) const;
+
+ /**
+ * Returns true if this FieldRef has any numeric path components.
+ */
+ bool hasNumericPathComponents() const;
+
+ /**
+ * Returns the positions of all numeric path components, starting from the given position.
+ */
+ std::set<size_t> getNumericPathComponents(size_t startPart = 0) const;
+
+ /**
* Returns a StringData of the full dotted field in its current state (i.e., some parts may
* have been replaced since the parse() call).
*/