diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/FieldNames.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/FieldNames.cs index b811bdee0..7f92cd16a 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/FieldNames.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/FieldNames.cs @@ -32,7 +32,7 @@ public sealed class FieldNames : ReadonlyList "translationStatusAverage" ]; - public static readonly new FieldNames Empty = new FieldNames(new List()); + public static readonly new FieldNames Empty = new FieldNames([]); private FieldNames() { diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs index fa92d9f82..1eed5872b 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs @@ -186,12 +186,19 @@ public static class Extensions foreach (var field in fields) { - var dataField = - FieldNames.IsDataField(field, out var fieldName) ? - fieldName : - field; - - yield return $"{dataPrefix}.{dataField}"; + var actualFieldName = field; + // Only add data fields, because we add all meta fields anyway. + if (FieldNames.IsDataField(field, out var dataField)) + { + actualFieldName = dataField; + } + + var fullName = $"{dataPrefix}.{actualFieldName}"; + + if (!MetaFields.ContainsKey(fullName)) + { + yield return fullName; + } } } @@ -203,13 +210,14 @@ public static class Extensions foreach (var field in allFields) { // If there is at least one field that is a prefix of the current field, we cannot add that. - if (addedFields.Exists(x => field.StartsWith(x, StringComparison.OrdinalIgnoreCase))) + if (addedFields.Exists(x => field.StartsWith(x, StringComparison.Ordinal))) { continue; } projections.Add(projector.Include(field)); + // Track added prefixes. addedFields.Add(field); } } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/MongoDb/ExtensionsTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/MongoDb/ExtensionsTests.cs index 682390102..de7a36476 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/MongoDb/ExtensionsTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/MongoDb/ExtensionsTests.cs @@ -51,6 +51,22 @@ public class ExtensionsTests AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.myField' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }"); } + [Fact] + public void Should_build_projection_with_status_data_field() + { + var projection = ExtensionSut.BuildProjection2(["data.Status"]); + + AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.Status' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }"); + } + + [Fact] + public void Should_build_projection_with_meta_status_field() + { + var projection = ExtensionSut.BuildProjection2(["status"]); + + AssertProjection(projection, "{ '_ai' : 1, '_id' : 1, '_si' : 1, 'ai' : 1, 'cb' : 1, 'ct' : 1, 'dl' : 1, 'do.status' : 1, 'id' : 1, 'is' : 1, 'mb' : 1, 'mt' : 1, 'ns' : 1, 'rf' : 1, 'sa' : 1, 'si' : 1, 'sj' : 1, 'ss' : 1, 'ts' : 1, 'vs' : 1 }"); + } + private static void AssertProjection(ProjectionDefinition projection, string expected) { var rendered =