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
| { | |
| foodItem: 'Purple pancakes', | |
| nutrients: [ | |
| { name: 'protein', amount: 100 }, | |
| { name: 'carbohydate', amount: 1000 } | |
| ] | |
| } |
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
| { | |
| foodItem: 'Purple pancakes', | |
| nutrients: [ | |
| { name: 'protein', amount: 100 }, | |
| { name: 'carbohydate', amount: 1000 } | |
| ] | |
| } |
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
| { | |
| foodItem: 'Purple pancakes', | |
| nutrients: { | |
| protein: { amount: 100 } | |
| carbohydrate: { amount: 1000 } | |
| } | |
| } |
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
| public class FoodItem | |
| { | |
| [BsonId] | |
| public string FoodId { get; set; } | |
| public string FoodGroupId { get; set; } | |
| public FoodGroup Group { get; set; } | |
| public string Description { get; set; } | |
| public string ShortDescription { get; set; } | |
| public string CommonNames { get; set; } |
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
| public void SerializeNutrients() | |
| { | |
| var root = new BsonDocument() { {"nutrients", new BsonDocument()} }; | |
| foreach (var nutrient in this.Nutrients) | |
| { | |
| if (string.IsNullOrWhiteSpace(nutrient.Definition.TagName)) | |
| { | |
| continue; | |
| } | |
| root["nutrients"][nutrient.Definition.TagName] = |
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
| public void DeserializeNutrients(string tag = null) | |
| { | |
| var elements = this.NutrientDoc["nutrients"].AsBsonDocument; | |
| var list = new List<Nutrient>(); | |
| foreach (var element in elements.Elements) | |
| { | |
| if (!string.IsNullOrWhiteSpace(tag)) { | |
| if (element.Name != tag) { | |
| continue; | |
| } |
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
| var projection = Builders<FoodItem>.Projection | |
| .Include(fi => fi.FoodId) | |
| .Include(fi => fi.FoodGroupId) | |
| .Include(fi => fi.Description) | |
| .Include(fi => fi.ShortDescription); | |
| var query = db.GetCollection<FoodItem>(Collections.GetCollectionName<FoodItem>()); | |
| var findFluent = query.Find(fi => fi.Description.Contains(search)); | |
| var projectedQuery = findFluent.Limit(100).Project(projection); | |
| await projectedQuery.ForEachAsync(item => { // do something }); |
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
| var sort = Builders<BsonDocument>.Sort.Descending($"NutrientDoc.nutrients.{tag}.amount"); | |
| var projection = Builders<BsonDocument>.Projection | |
| .Include("_id") | |
| .Include("FoodGroupId") | |
| .Include("ShortDescription") | |
| .Include("Description") | |
| .Include($"NutrientDoc.nutrients.{tag}"); | |
| var query = coll.Find(_ => true) | |
| .Project(projection) | |
| .Sort(sort) |
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
| { | |
| "bindings": [ | |
| { | |
| "type": "table", | |
| "name": "keyTable", | |
| "tableName": "urls", | |
| "partitionKey": "1", | |
| "rowKey": "KEY", | |
| "take": 1, | |
| "connection": "AzureWebJobsStorage", |
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.WindowsAzure.Storage.Table; | |
| public class NextId : TableEntity | |
| { | |
| public int Id { get; set; } | |
| } | |
| public class ShortUrl : TableEntity | |
| { | |
| public string Url { get; set; } |