public void DeleteFromChart(string id) { MongodbFunctions mongo = new MongodbFunctions(); Database.DomainModel.User user = mongo.GetUser(User.Identity.Name); Database.DomainModel.Order order = mongo.GetOpenOrder(user.Id); order.Products.Remove(new MongoDBRef("products", new ObjectId(id))); if (order.Products.Count > 0) { mongo.RemoveProduct(order); } else { mongo.DeleteOrder(order.Id); } }