1
- namespace DocumentDB . Samples . Queries . Spatial
1
+ namespace DocumentDB . Samples . Queries . JavaScript
2
2
{
3
3
using System ;
4
4
using System . Collections . Generic ;
15
15
using Newtonsoft . Json . Serialization ;
16
16
17
17
/// <summary>
18
- /// This sample demonstrates the use of geospatial indexing and querying with Azure DocumentDB. We
19
- /// look at how to store Points using the classes in the Microsoft.Azure.Documents.Spatial namespace,
20
- /// how to enable a collection for geospatial indexing, and how to query for WITHIN and DISTANCE
21
- /// using SQL and LINQ.
18
+ /// This sample demonstrates the use of JavaScript language integrated queries with Azure DocumentDB.
22
19
/// </summary>
23
20
public class Program
24
21
{
@@ -42,26 +39,6 @@ public class Program
42
39
/// </summary>
43
40
private static readonly string AuthorizationKey = ConfigurationManager . AppSettings [ "AuthorizationKey" ] ;
44
41
45
- /// <summary>
46
- /// Gets an indexing policy with spatial enabled. You can also configure just certain paths for spatial indexing, e.g. Path = "/location/?"
47
- /// </summary>
48
- private static readonly IndexingPolicy IndexingPolicyWithSpatialEnabled = new IndexingPolicy
49
- {
50
- IncludedPaths = new System . Collections . ObjectModel . Collection < IncludedPath > ( )
51
- {
52
- new IncludedPath
53
- {
54
- Path = "/*" ,
55
- Indexes = new System . Collections . ObjectModel . Collection < Index > ( )
56
- {
57
- new SpatialIndex ( DataType . Point ) ,
58
- new RangeIndex ( DataType . Number ) { Precision = - 1 } ,
59
- new RangeIndex ( DataType . String ) { Precision = - 1 }
60
- }
61
- }
62
- }
63
- } ;
64
-
65
42
/// <summary>
66
43
/// Gets the client to use.
67
44
/// </summary>
@@ -99,7 +76,7 @@ public static void Main(string[] args)
99
76
}
100
77
101
78
/// <summary>
102
- /// Run the geospatial demo .
79
+ /// Run the JavaScript language integrated queries samples .
103
80
/// </summary>
104
81
/// <param name="databaseId">The database Id.</param>
105
82
/// <param name="collectionId">The collection Id.</param>
@@ -130,7 +107,8 @@ private static async Task RunDemoAsync(string databaseId, string collectionId)
130
107
Console . WriteLine ( "Projection query returned: {0}" , JsonConvert . SerializeObject ( projectionQueryResult , Formatting . Indented ) ) ;
131
108
132
109
// Run a query using filter and map (using chaining)
133
- object chainQueryResult = await QueryScalar ( collection . SelfLink ,
110
+ object chainQueryResult = await QueryScalar (
111
+ collection . SelfLink ,
134
112
@"__.chain()
135
113
.filter(function(person) { return person.firstName === 'Andrew'; })
136
114
.map(function(person) { return { familyName: person.lastName, address: person.address }; })
@@ -139,7 +117,8 @@ private static async Task RunDemoAsync(string databaseId, string collectionId)
139
117
Console . WriteLine ( "Chain (filter & projection) query returned: {0}" , JsonConvert . SerializeObject ( chainQueryResult , Formatting . Indented ) ) ;
140
118
141
119
// Run a chained filter, map and sorting (using chaining)
142
- object sortQueryResult = await QueryScalar ( collection . SelfLink ,
120
+ object sortQueryResult = await QueryScalar (
121
+ collection . SelfLink ,
143
122
@"__.chain()
144
123
.filter(function(person) { return person.firstName === 'Andrew' || person.firstName === 'Ryan'; })
145
124
.sortBy(function(person) { return person.lastName; })
@@ -205,9 +184,13 @@ private static async Task<DocumentCollection> GetCollection(string databaseLink,
205
184
/// Run a query that returns a single document, and display it
206
185
/// </summary>
207
186
/// <param name="collectionLink">The collection self-link</param>
208
- /// <param name="query">The query to run</param>
187
+ /// <param name="javascriptQuery">The query to run</param>
188
+ /// <returns>The result of the query as an object.</returns>
209
189
private static async Task < object > QueryScalar ( string collectionLink , string javascriptQuery )
210
190
{
191
+ // JavaScript integrated queries are supported using the server side SDK, so you'll be using
192
+ // them within stored procedures and triggers. Here we show them standalone just to demonstrate
193
+ // how to use the functional-Underscore.js style query API
211
194
string javaScriptFunctionStub = string . Format ( "function() {{ {0}; }}" , javascriptQuery ) ;
212
195
string singleQuerySprocName = "query" ;
213
196
@@ -240,7 +223,8 @@ private static async Task<object> QueryScalar(string collectionLink, string java
240
223
/// Create a document from JSON string
241
224
/// </summary>
242
225
/// <param name="collectionLink">The collection self-link</param>
243
- /// <param name="query">The JSON to create</param>
226
+ /// <param name="json">The JSON to create</param>
227
+ /// <returns>The Task for asynchronous execution.</returns>
244
228
private static async Task CreateDocumentAsync ( string collectionLink , string json )
245
229
{
246
230
using ( System . IO . MemoryStream ms = new MemoryStream ( System . Text . Encoding . UTF8 . GetBytes ( json ) ) )
0 commit comments