I’ve a entity class stored in MongoDB that looks similar to these:
public class Theme
{
public ObjectId Id { get; set; }
public string Description { get; set; }
public string Title { get; set; }
public List<Comment> CommentList { get; set; }
}
public class Comment
{
public string Content { get; set; }
public string Creator { get; set; }
public string Date { get; set; }
}
Using the MongoDB C# driver,and based on the model, how can i resolve for the following questions:
- Update a comment of the theme, eg:
theme1.CommetList[10].Creator = "Jack" - How to page for the array object
Thanks.
Wentel
@Andrew Orsich
Thanks for your help.
And there is another trouble:
var query = Query.EQ("Id", id); //The 'id' type is ObjectId
List<Theme> newDatas = themeCollection.FindAs<Theme>(query).ToList();
Theme newData = themeCollection.FindOneByIdAs<Theme>(allDatas[0].Id);
Result: ‘newDatas’ is null and ‘newData’ has data, why?
1.Using positional operator:
Also you probably need to add id to the Comment class. In this case you can updated matched by query comment like this:
2.You can load entire theme and do paging of comments from c# using linq for example. Or you can also use $slice like this: