public async Task AggregateUnwindOperationWithMatch(int intField, int exceptedCount) { var testData = CreateTestData().ToList(); var collection = _mongoCollectionProvider.GetCollection(nameof(FindWithArrayAnyFilter), testData); collection.InsertOne(new SimpleTestDocument() { AnotherChildrenDocuments = new[] { new AnotherChildDocument() { StringField = "Hi", Image = new Image { Name = "10" }, }, new AnotherChildDocument() { StringField = "Bye", Image = new Image { Name = "16" }, }, }, IntField = intField, }); var currentProjection = new BsonDocumentProjectionDefinition <BsonDocument>( BsonDocument.Parse("{ Image: \"$AnotherChildrenDocuments.Image\", _id: 0, value: 1992 }")); var result = collection.Aggregate() .Match(x => x.IntField == 1) .Unwind(x => x.AnotherChildrenDocuments) .Match(x => x["AnotherChildrenDocuments.StringField"] == "Hi") .Project(currentProjection) .As <SimpleTestDocument>() .ToList(); Assert.Equal(exceptedCount, result.Count); }
private IAsyncCursor <TProjection> CreateCursor() { var fluentCursor = _fluentCursor; if (!string.IsNullOrEmpty(_textScoreProperty)) { var projectionDefinition = fluentCursor.Options.Projection; var textScoreProjection = new BsonDocument(_textScoreProperty, new BsonDocument("$meta", "textScore")); var textScoreProjectionDefinition = new BsonDocumentProjectionDefinition <TDocument, TProjection>(textScoreProjection); fluentCursor.Options.Projection = (projectionDefinition != null) ? MongoHelpers.Combine(projectionDefinition, textScoreProjectionDefinition) : textScoreProjectionDefinition; } if (_sortDefinition != null) { fluentCursor = _fluentCursor.Sort(_sortDefinition); } return(fluentCursor.ToCursor()); }