Created
August 22, 2014 07:31
-
-
Save joeriks/bb2c355be386ff3b75ad to your computer and use it in GitHub Desktop.
Test DocumentDb from trywebsites.azurewebsites.net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Time to create connection and get collection 671 | |
| Time to perform simple query 126 | |
| Andersen family: | |
| {"id":"AndersenFamily","lastName":"Andersen","parents":[{"firstName":"Thomas"},{"firstName":"Mary Kay"}],"children":[{"firstName":"John","gender":"male","grade":7}],"pets":[{"givenName":"Fluffy"}],"address":{"country":"USA","state":"WA","city":"Seattle"},"_rid":"==","_ts":1408692077,"_self":"dbs/8qgSAA==/colls/=/docs/==/","_etag":"00000c00-0000-0000-0000-53f6ef6d0000","_attachments":"attachments/"} | |
| Time to convert and print 0 | |
| Time for next query 104 | |
| First male child: | |
| {"firstName":"John","gender":"male","grade":7} | |
| Time to convert and print 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @using Microsoft.Azure.Documents | |
| @using Microsoft.Azure.Documents.Client | |
| @using Microsoft.Azure.Documents.Linq | |
| @using Newtonsoft.Json | |
| @using Newtonsoft.Json.Bson | |
| @using Newtonsoft.Json.Converters | |
| @using Newtonsoft.Json.Linq | |
| @using Newtonsoft.Json.Schema | |
| @using Newtonsoft.Json.Serialization | |
| @using System.Threading.Tasks | |
| @{ | |
| string endpoint = x; | |
| string authKey = y; | |
| dynamic andersonFamily = JsonConvert.DeserializeObject(@" | |
| { | |
| 'id': 'AndersenFamily', | |
| 'lastName': 'Andersen', | |
| 'parents': [ | |
| { 'firstName': 'Thomas' }, | |
| { 'firstName': 'Mary Kay' } | |
| ], | |
| 'children': [ | |
| { 'firstName': 'John', 'gender': 'male', 'grade': 7 } | |
| ], | |
| 'pets': [ | |
| { 'givenName': 'Fluffy' } | |
| ], | |
| 'address': { 'country': 'USA', 'state': 'WA', 'city': 'Seattle' } | |
| }"); | |
| dynamic wakefieldFamily = JsonConvert.DeserializeObject(@" | |
| { | |
| 'id': 'WakefieldFamily', | |
| 'parents': [ | |
| { 'familyName': 'Wakefield', 'givenName': 'Robin' }, | |
| { 'familyName': 'Miller', 'givenName': 'Ben' } | |
| ], | |
| 'children': [ | |
| { | |
| 'familyName': 'Wakefield', | |
| 'givenName': 'Jesse', | |
| 'gender': 'female', | |
| 'grade': 1 | |
| }, | |
| { | |
| 'familyName': 'Miller', | |
| 'givenName': 'Lisa', | |
| 'gender': 'female', | |
| 'grade': 8 | |
| } | |
| ], | |
| 'pets': [ | |
| { 'givenName': 'Goofy' }, | |
| { 'givenName': 'Shadow' } | |
| ], | |
| 'address': { 'country': 'USA', 'state': 'NY', 'county': 'Manhattan', 'city': 'NY' } | |
| }"); | |
| using (var client = new DocumentClient(new Uri(endpoint), authKey)) | |
| { | |
| var database = new Microsoft.Azure.Documents.Database { Id = "FromAzure" }; | |
| database = client.CreateDatabaseAsync(database).Result; | |
| var collection = new DocumentCollection { Id = "Families" }; | |
| collection = client.CreateDocumentCollectionAsync(database.SelfLink, collection).Result; | |
| client.CreateDocumentAsync(collection.SelfLink, andersonFamily).Wait(); | |
| client.CreateDocumentAsync(collection.SelfLink, wakefieldFamily).Wait(); | |
| } | |
| } | |
| <p>Done</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @using Microsoft.Azure.Documents | |
| @using Microsoft.Azure.Documents.Client | |
| @using Microsoft.Azure.Documents.Linq | |
| @using Newtonsoft.Json | |
| @using Newtonsoft.Json.Bson | |
| @using Newtonsoft.Json.Converters | |
| @using Newtonsoft.Json.Linq | |
| @using Newtonsoft.Json.Schema | |
| @using Newtonsoft.Json.Serialization | |
| @using System.Threading.Tasks | |
| @using System.Diagnostics | |
| @{ | |
| string endpoint = x; | |
| string authKey = y; | |
| using (var client = new DocumentClient(new Uri(endpoint), authKey)) | |
| { | |
| var s = Stopwatch.StartNew(); | |
| var database = client.CreateDatabaseQuery().Where (c => c.Id=="FromAzure").AsEnumerable().Single (); | |
| var collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where (c=>c.Id=="Families").AsEnumerable().Single ( ); | |
| <p>Time to create connection and get collection @s.ElapsedMilliseconds</p> | |
| s.Restart(); | |
| var query = client.CreateDocumentQuery(collection.SelfLink, "SELECT * FROM Families f WHERE f.id = 'AndersenFamily'"); | |
| var family = query.AsEnumerable().Single (); | |
| <p>Time to perform simple query @s.ElapsedMilliseconds</p> | |
| s.Restart(); | |
| <p>Andersen family:</p> | |
| <p>@family</p> | |
| <p>Time to convert and print @s.ElapsedMilliseconds</p> | |
| s.Restart(); | |
| query = client.CreateDocumentQuery(collection.DocumentsLink, "SELECT * FROM c IN Families.children WHERE c.gender='male'"); | |
| var child = query.AsEnumerable().FirstOrDefault(); | |
| <p>Time for next query @s.ElapsedMilliseconds</p> | |
| s.Restart(); | |
| <p>First male child:</p> | |
| <p>@child</p> | |
| <p>Time to convert and print @s.ElapsedMilliseconds</p> | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So does creating a new documentdb