public Shirt createShirtFromBson(BsonDocument product) { var variants = new Dictionary<string, ObjectId>(); foreach (var variant in new String[] { "XS", "S", "M", "L", "XL" }) { variants.Add(variant, product["variants"].AsBsonArray.First(x => x.AsBsonDocument.Contains(variant))[variant].AsObjectId); } var shirt = new Shirt() { Id = product["id"].AsObjectId, Title = product["title"].AsString, Description = product["description"].AsString, Photos = product["images"].AsBsonArray.Select(x => x.ToString()).ToArray(), Handle = product["handle"].AsString, Price = product["price"].AsDouble, Stock = product["stock"].AsInt32, Type = product["type"].AsString, Display = bool.Parse(product["display"].AsString), Variants = variants }; return shirt; }
public void UpdateShirt(Shirt shirt) { var filter = new BsonDocument("id", shirt.Id); var update = Builders<BsonDocument>.Update.Set("images", new BsonArray(shirt.Photos)); collection.FindOneAndUpdateAsync(filter, update).Wait(); }