Last active
August 29, 2015 14:05
-
-
Save joeriks/d15a2d87fcc3ccfc6635 to your computer and use it in GitHub Desktop.
Experimenting with DocumentDb - basic write and read (from ScottGu example) - and timing from local pc
This file contains 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 2513 ms | |
Time to perform simple query 448 ms | |
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": ... | |
"_attachments": "attachments/" | |
} | |
Time to convert and print 13 ms | |
Time for next query 449 ms | |
First male child: | |
{ | |
"firstName": "John", | |
"gender": "male", | |
"grade": 7 | |
} | |
Time to convert and print 2 ms |
This file contains 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 (var client = new DocumentClient(new Uri(endpoint), authKey)) | |
{ | |
var s = Stopwatch.StartNew(); | |
var database = client.CreateDatabaseQuery().Where (c => c.Id=="AnotherDb").AsEnumerable().Single (); | |
var collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where (c=>c.Id=="Families").AsEnumerable().Single ( ); | |
Console.WriteLine("Time to create connection and get collection {0} ms",s.ElapsedMilliseconds); | |
s.Restart(); | |
var query = client.CreateDocumentQuery(collection.SelfLink, "SELECT * FROM Families f WHERE f.id = 'AndersenFamily'"); | |
var family = query.AsEnumerable().Single (); | |
Console.WriteLine("Time to perform simple query {0} ms",s.ElapsedMilliseconds); | |
s.Restart(); | |
Console.WriteLine("Andersen family:"); | |
Console.WriteLine(((JObject)family).ToString()); | |
Console.WriteLine("Time to convert and print {0} ms",s.ElapsedMilliseconds); | |
s.Restart(); | |
query = client.CreateDocumentQuery(collection.DocumentsLink, "SELECT * FROM c IN Families.children WHERE c.gender='male'"); | |
var child = query.AsEnumerable().FirstOrDefault(); | |
Console.WriteLine("Time for next query {0} ms",s.ElapsedMilliseconds); | |
s.Restart(); | |
Console.WriteLine("First male child:"); | |
Console.WriteLine(((JObject)child).ToString()); | |
Console.WriteLine("Time to convert and print {0} ms",s.ElapsedMilliseconds); | |
} |
This file contains 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 (var client = new DocumentClient(new Uri(endpoint), authKey)) | |
{ | |
var database = new Database { Id = "AnotherDb" }; | |
database = await client.CreateDatabaseAsync(database); | |
var collection = new DocumentCollection { Id = "Families" }; | |
collection = await client.CreateDocumentCollectionAsync(database.SelfLink, collection); | |
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' } | |
}" | |
); | |
await client.CreateDocumentAsync(collection.SelfLink, andersonFamily); | |
await client.CreateDocumentAsync(collection.SelfLink, wakefieldFamily); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment