summaryrefslogtreecommitdiff
path: root/src/mongo/db/namespace_string.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/namespace_string.h')
-rw-r--r--src/mongo/db/namespace_string.h25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h
index 5a891df19c0..65d23736dee 100644
--- a/src/mongo/db/namespace_string.h
+++ b/src/mongo/db/namespace_string.h
@@ -96,6 +96,16 @@ public:
MaxNsCollectionLen = MaxNsLen - 7 /*strlen(".$extra")*/,
};
+ /**
+ * DollarInDbNameBehavior::allow is deprecated.
+ * Please use DollarInDbNameBehavior::disallow and check explicitly for any DB names that must
+ * contain a $.
+ */
+ enum class DollarInDbNameBehavior {
+ Disallow,
+ Allow, // Deprecated
+ };
+
StringData db() const;
StringData coll() const;
@@ -165,7 +175,7 @@ public:
* valid.
*/
bool isValid() const {
- return validDBName(db()) && !coll().empty();
+ return validDBName(db(), DollarInDbNameBehavior::Allow) && !coll().empty();
}
bool operator==(const std::string& nsIn) const {
@@ -220,12 +230,12 @@ public:
/**
* Returns true for DBs with special meaning to mongodb.
*/
- static bool internalDb(StringData ns) {
- if (ns == "admin")
+ static bool internalDb(StringData db) {
+ if (db == "admin")
return true;
- if (ns == "local")
+ if (db == "local")
return true;
- if (ns == "config")
+ if (db == "config")
return true;
return false;
}
@@ -242,9 +252,12 @@ public:
* foo"bar
*
* @param db - a possible database name
+ * @param DollarInDbNameBehavior - please do not change the default value. DB names that must
+ * contain a $ should be checked explicitly.
* @return if db is an allowed database name
*/
- static bool validDBName(StringData dbin);
+ static bool validDBName(StringData db,
+ DollarInDbNameBehavior behavior = DollarInDbNameBehavior::Disallow);
/**
* Takes a fully qualified namespace (ie dbname.collectionName), and returns true if