Post類:更新特定集合項目的性質與FindAndModify
public class Post
{
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonRepresentation(BsonType.ObjectId)]
public string CreatorId { get; set; }
public string CreatorName { get; set; }
public string Text { get; set; }
public bool IsPublic { get; set; }
public ICollection<Comment> Comments { get; set; }
public DateTime CreationDate { get { return ObjectId.Parse(Id).CreationTime; } }
public DateTime? DeletionDate { get; set; }
}
評論類:
public class Comment
{
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonRepresentation(BsonType.ObjectId)]
public string CreatorId { get; set; }
public string CreatorName { get; set; }
public string Text { get; set; }
public DateTime CreationDate { get { return ObjectId.Parse(Id).CreationTime; } }
public DateTime? DeletionDate { get; set; }
}
我想找個設置Comment
的DeletionDate
財產Post.Comments
內因爲Comment.Id
和Comment.CreatorId
等於給定的參數。
我該怎麼做?
這並沒有工作,因爲它是,但感謝你提的位置操作,這是需要我的更新命令。我用'「$ elemMatch」'解決了它。 – 2014-10-18 16:52:28