summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/expression.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/expression.h')
-rw-r--r--src/mongo/db/pipeline/expression.h71
1 files changed, 42 insertions, 29 deletions
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index a0a2d08bdee..cb68e7cef5b 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -73,16 +73,37 @@ class DocumentSource;
* An expression registered this way can be used in any featureCompatibilityVersion and will be
* considered part of the stable API.
*/
-#define REGISTER_STABLE_EXPRESSION(key, parser) \
- MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, \
- ("BeginExpressionRegistration"), \
- ("EndExpressionRegistration")) \
- (InitializerContext*) { \
- Expression::registerExpression("$" #key, \
- (parser), \
- AllowedWithApiStrict::kAlways, \
- AllowedWithClientType::kAny, \
- boost::none); \
+#define REGISTER_STABLE_EXPRESSION(key, parser) \
+ REGISTER_EXPRESSION_CONDITIONALLY(key, \
+ parser, \
+ AllowedWithApiStrict::kAlways, \
+ AllowedWithClientType::kAny, \
+ boost::none, \
+ true);
+
+/**
+ * Like REGISTER_EXPRESSION_WITH_MIN_VERSION, except you can also specify a condition,
+ * evaluated during startup, that decides whether to register the parser.
+ *
+ * For example, you could check a feature flag, and register the parser only when it's enabled.
+ *
+ * Note that the condition is evaluated only once, during a MONGO_INITIALIZER. Don't specify
+ * a condition that can change at runtime, such as FCV. (Feature flags are ok, because they
+ * cannot be toggled at runtime.)
+ *
+ * This is the most general REGISTER_EXPRESSION* macro, which all others should delegate to.
+ */
+#define REGISTER_EXPRESSION_CONDITIONALLY( \
+ key, parser, allowedWithApiStrict, allowedClientType, minVersion, ...) \
+ MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, \
+ ("BeginExpressionRegistration"), \
+ ("EndExpressionRegistration")) \
+ (InitializerContext*) { \
+ if (!(__VA_ARGS__)) { \
+ return; \
+ } \
+ Expression::registerExpression( \
+ "$" #key, (parser), (allowedWithApiStrict), (allowedClientType), (minVersion)); \
}
/**
@@ -106,30 +127,22 @@ class DocumentSource;
* parser and enforce the 'sometimes' behavior during that invocation. No extra validation will be
* done here.
*/
-#define REGISTER_EXPRESSION_WITH_MIN_VERSION( \
- key, parser, allowedWithApiStrict, allowedClientType, minVersion) \
- MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, \
- ("BeginExpressionRegistration"), \
- ("EndExpressionRegistration")) \
- (InitializerContext*) { \
- Expression::registerExpression( \
- "$" #key, (parser), (allowedWithApiStrict), (allowedClientType), (minVersion)); \
- }
+#define REGISTER_EXPRESSION_WITH_MIN_VERSION( \
+ key, parser, allowedWithApiStrict, allowedClientType, minVersion) \
+ REGISTER_EXPRESSION_CONDITIONALLY( \
+ key, parser, allowedWithApiStrict, allowedClientType, minVersion, true)
/**
* Registers a Parser only if test commands are enabled. Use this if your expression is only used
* for testing purposes.
*/
-#define REGISTER_TEST_EXPRESSION(key, allowedWithApiStrict, allowedClientType, parser) \
- MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, \
- ("BeginExpressionRegistration"), \
- ("EndExpressionRegistration")) \
- (InitializerContext*) { \
- if (getTestCommandsEnabled()) { \
- Expression::registerExpression( \
- "$" #key, (parser), (allowedWithApiStrict), (allowedClientType), boost::none); \
- } \
- }
+#define REGISTER_TEST_EXPRESSION(key, allowedWithApiStrict, allowedClientType, parser) \
+ REGISTER_EXPRESSION_CONDITIONALLY(key, \
+ parser, \
+ allowedWithApiStrict, \
+ allowedClientType, \
+ boost::none, \
+ getTestCommandsEnabled());
class Expression : public RefCountable {
public: