I have a Profiles
document collection with array of the following documents :
public class Profile2MailList
{
[BsonElement(elementName: "listId")]
[BsonRequired]
public int MailListId;
[BsonElement(elementName: "status")]
[BsonRequired]
public int Status;
[BsonElement(elementName: "subscriptionDate")]
[BsonRequired]
public DateTime SubscriptionDate;
}
in each Profile
.
I need to add to the Profile2MailList
array a new Profile2MailList
document in each Profile
based on Profile2MailList
which already contains in a certain Profile
. So i need to
- Take needed profiles from
Profiles
collection - Update
Profile2Maillist
array in eachProfile
Run update command How can i perform that action via
C# 2.0 MongoDb Driver
. I haveMongoDb v 3.0.2
. I try to make it by the following way :List<Profile> listProfiles = new List<Profile>(); foreach (Profile item in profiles) { item.MailLists.ToList().Add(new Profile2MailList(maillistId, item.MailLists.FirstOrDefault().Status)); var t = item; listProfiles.Add(t); } dbCollection.UpdateManyAsync(listProfiles)