@@ -36,15 +36,51 @@ public async Task<List<Movie>> GetMovies(double minScore, Genre genre, string ti
3636 . Ascending ( m => m . Score )
3737 . Descending ( m => m . Title ) ;
3838
39- var movies = await moviesCollection . Find ( filter ) . Sort ( sort ) . ToListAsync ( ) ;
39+ var projection = Builders < Movie > . Projection
40+ . Include ( m => m . Title )
41+ . Exclude ( m => m . Genre ) ;
42+
43+ // MQL is displayed for 'filter' and 'sort' variables
44+ var movies = await moviesCollection
45+ . Find ( filter )
46+ . Sort ( sort )
47+ . Project ( projection )
48+ . As < Movie > ( )
49+ . ToListAsync ( ) ;
50+
51+ // Fluent API
52+ _ = moviesCollection
53+ . Find ( u => u . Producer . Contains ( "Nolan" ) )
54+ . SortBy ( u => u . Score )
55+ . ThenBy ( u => u . Title ) ;
4056
4157 return movies ;
4258 }
4359
60+ public void VariablesTracking ( )
61+ {
62+ var mongoClient = new MongoClient ( @"mongodb://localhost:27017" ) ;
63+ var db = mongoClient . GetDatabase ( "testdb" ) ;
64+ var moviesCollection = db . GetCollection < Movie > ( "movies" ) ;
65+
66+ var filterScore = Builders < Movie > . Filter . Gt ( p => p . Score , 5 ) ;
67+ var filterTitle = Builders < Movie > . Filter . Regex ( p => p . Title , "Summer" ) ;
68+ var filterGenre = Builders < Movie > . Filter . Eq ( p => p . Genre , Genre . Comedy ) ;
69+
70+ // Each filter variable tracks its MQL
71+ var filterCombined = filterTitle | filterScore | filterGenre ;
72+
73+ // MQL for the combined filter
74+ moviesCollection . Find ( filterCombined ) ;
75+ }
76+
4477 public void NotSupportedFilter ( )
4578 {
4679 // Not supported filter expression (analyzer provides warning)
4780 var filter = Builders < Movie > . Filter . Gt ( m => m . Reviews . Length , 2 ) ;
81+
82+ // Not supported filter expression (analyzer provides warning)
83+ filter = Builders < Movie > . Filter . AnyNin ( t => t . Reviews , null ) ;
4884 }
4985 }
5086}
0 commit comments