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