diff --git a/src/MongoDB.Analyzer/Core/ConstantsMapper.cs b/src/MongoDB.Analyzer/Core/ConstantsMapper.cs index f90e8216..68e85289 100644 --- a/src/MongoDB.Analyzer/Core/ConstantsMapper.cs +++ b/src/MongoDB.Analyzer/Core/ConstantsMapper.cs @@ -23,6 +23,8 @@ internal sealed class ConstantsMapper private const string RegexLookahead = "(?![\\w\"\\.])"; private const string RegexLookbehind = "(? _originalToSyntax; private IDictionary _mqlRemapping; @@ -222,6 +224,7 @@ private void AddMapping(string source, string target, bool isString) { _mqlRemapping[$"{RegexLookbehind}\"{source}\"{RegexLookahead}"] = target; _mqlRemapping[$"/{source}/"] = $"/{target}/"; + _mqlRemapping[$"{RegexLookbehind}\"{source}{WildcardRegex}\"{RegexLookahead}"] = $"{target}{WildcardSuffix}"; } else { diff --git a/tests/MongoDB.Analyzer.Tests.Common.TestCases/Builders/BuildersIndexKeys.cs b/tests/MongoDB.Analyzer.Tests.Common.TestCases/Builders/BuildersIndexKeys.cs index 91576b37..91fdfc11 100644 --- a/tests/MongoDB.Analyzer.Tests.Common.TestCases/Builders/BuildersIndexKeys.cs +++ b/tests/MongoDB.Analyzer.Tests.Common.TestCases/Builders/BuildersIndexKeys.cs @@ -83,6 +83,20 @@ public void Text() _ = Builders.IndexKeys.Text(u => u.Address).Text("Vehicle"); } + [BuildersMQL("{ \"$**\" : 1 }")] + [BuildersMQL("{ \"Address.$**\" : 1 }")] + [BuildersMQL("{ \"SiblingsCount.$**\" : 1 }")] + [BuildersMQL("{ wildcardField.$** : 1 }")] + public void Wildcard() + { + _ = Builders.IndexKeys.Wildcard(); + _ = Builders.IndexKeys.Wildcard("Address"); + _ = Builders.IndexKeys.Wildcard(p => p.SiblingsCount); + + var wildcardField = "Vehicle"; + _ = Builders.IndexKeys.Wildcard(wildcardField); + } + [BuildersMQL("{ \"Name\" : \"text\", \"LastName\" : \"hashed\", \"Vehicle\" : \"2d\", \"Address\" : 1 }")] [BuildersMQL("{ \"Name\" : \"2d\", \"LastName\" : \"2dsphere\", \"Vehicle\" : \"text\", \"Address\" : -1, \"SiblingsCount\" : \"hashed\", \"TicksSinceBirth\" : 1 }")] [BuildersMQL("{ \"Name\" : \"2d\", \"LastName\" : \"2d\", \"Address\" : \"text\", \"Vehicle\" : \"text\" }")]