File tree Expand file tree Collapse file tree 4 files changed +423
-289
lines changed
content/manual/manual/source
includes/driver-examples/aggregation
reference/operator/aggregation Expand file tree Collapse file tree 4 files changed +423
-289
lines changed Original file line number Diff line number Diff line change @@ -154,7 +154,36 @@ public static void FacetStage()
154
154
. Facet ( bucketFacet , countFacet ) ;
155
155
// end facet
156
156
}
157
-
157
+
158
+ public static void GeoNearStage ( )
159
+ {
160
+ // start geoNear
161
+ var pipeline = new EmptyPipelineDefinition < Theater > ( )
162
+ . GeoNear (
163
+ GeoJson . Point ( GeoJson . Geographic ( - 74.1 , 40.95 ) ) ,
164
+ new GeoNearOptions < Theater , Theater >
165
+ {
166
+ DistanceField = "distance" ,
167
+ MaxDistance = 8000 ,
168
+ Key = "location.geo" ,
169
+ Query = Builders < Theater > . Filter . Eq ( t => t . Location . Address . State , "NJ" ) ,
170
+ } ) ;
171
+ // end geoNear
172
+
173
+ // start geoNear min
174
+ var pipeline = new EmptyPipelineDefinition < Theater > ( )
175
+ . GeoNear (
176
+ GeoJson . Point ( GeoJson . Geographic ( - 74.1 , 40.95 ) ) ,
177
+ new GeoNearOptions < Theater , Theater >
178
+ {
179
+ DistanceField = "distance" ,
180
+ MinDistance = 8000 ,
181
+ Key = "location.geo" ,
182
+ Query = Builders < Theater > . Filter . Eq ( t => t . Location . Address . State , "NJ" ) ,
183
+ } )
184
+ . Limit ( 4 ) ;
185
+ // end geoNear min
186
+ }
158
187
public static void GraphLookupStage ( )
159
188
{
160
189
// start graphLookupBasic
Original file line number Diff line number Diff line change
1
+ public class Theater
2
+ {
3
+ public ObjectId Id { get ; set ; }
4
+
5
+ [ BsonElement ( "theaterId" ) ]
6
+ public int TheaterId { get ; set ; }
7
+
8
+ [ BsonElement ( "location" ) ]
9
+ public Location Location { get ; set ; }
10
+
11
+ [ BsonElement ( "distance" ) ]
12
+ public double ? Distance { get ; set ; }
13
+ }
14
+
15
+ public class Location
16
+ {
17
+ [ BsonElement ( "address" ) ]
18
+ public Address Address { get ; set ; }
19
+
20
+ [ BsonElement ( "geo" ) ]
21
+ public GeoJsonPoint < GeoJson2DGeographicCoordinates > Geo { get ; set ; }
22
+ }
23
+
24
+ [ BsonIgnoreExtraElements ]
25
+ public class Address
26
+ {
27
+ [ BsonElement ( "city" ) ]
28
+ public string City { get ; set ; }
29
+
30
+ [ BsonElement ( "state" ) ]
31
+ public string State { get ; set ; }
32
+ }
Original file line number Diff line number Diff line change
1
+ The C# examples on this page use the ``sample_mflix.theaters `` collection
2
+ from the :atlas: `Atlas sample datasets </sample-data> `. To learn how to create a
3
+ free MongoDB Atlas cluster and load the sample datasets, see
4
+ :driver: `Get Started </csharp/current/quick-start/> ` in the MongoDB .NET/C#
5
+ Driver documentation.
6
+
7
+ The following ``Theater ``, ``Location ``, and ``Address `` classes model
8
+ the documents in the ``sample_mflix.theaters `` collection:
9
+
10
+ .. literalinclude :: /includes/driver-examples/aggregation/Theater.cs
11
+ :language: csharp
You can’t perform that action at this time.
0 commit comments