Retrieving a movie using BsonDocument objects in the driver


I tried to build a GetMovieAsync using BsonDocument objects. But I didn’t manage to write a proper matchStage. Could you help me to correct the following code ?

public async Task<Movie> GetMovieAsync(string movieId, CancellationToken cancellationToken = default)
{ var matchStage = new BsonDocument("$match", new BsonDocument(“Id”, movieId));
var pipeline = PipelineDefinition<Movie, Movie>.Create(new [ ] { matchStage });
return await _moviesCollection.Aggregate(pipeline).FirstOrDefaultAsync(cancellationToken);}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.