I have 2 classes:
public class Vote { public string VoteId { get; set; } public string Question { get; set; } public List<VoteAnswer> AnswerList { get; set; } }
AND:
public class VoteOption { public string OptionId { get; set; } public string OptionName { get; set; } public double VoteCount { get; set; } }
How can I update / delete a VoteOption in Vote , where VoteId = voteId and OptionId = optionId ? Using the C# driver.
First I get VoteOption:
var v = col.FindOneAs<Vote>(Query.EQ("VoteID", voteId)); VoteOption vo = v.AnswerList.Find(x => x.OptionId == optionId);
The end sets some value for it:
vo.OptionName = "some option chose"; vo.VoteCount = 1000;
But I do not know how the next step is to upgrade this vo to Vote parent .
And, if I want to delete this vo , show me this way!
Data in MongoDB:
{ "_id" : "460b3a7ff100", "Question" : "this is question?", "AnswerList" : [{ "OptionId" : "1", "OptionName" : "Option 1", "VoteCount" : 0.0 }, { "OptionId" : "2", "OptionName" : "Option 2", "VoteCount" : 0.0 }, { "OptionId" : "3", "OptionName" : "Option 3", "VoteCount" : 0.0 } }] }
source share