RavenDB internal assembly

I am new to RavenDB, and from my understanding, when you request a document, you will get the whole document (if you are not using some kind of index, etc.).

Scenario example

Take, for example, a script document in a blog where the document is as follows:

public class Blog { public string Id { get; set; } public string AuthorId { get; set; } public DateTime PublishedUTC { get; set; } public string Title { get; set; } public string Content { get; set; } public Comment[] Comments { get; set; } } public class Comment { public string Id { get; set; } public string AuthorId { get; set; } public DateTime PublishedUTC { get; set; } public string Content { get; set; } } 

Say we have a webpage /blogs/posts/ . The page displays a calculated set of blog entries and comments for each blog. I understand how to use paging in Blog documents using the Skip() and Take() methods. I would like to apply the swap logic to the internal Comments collection for each of the blog documents.

My questions

  • How can I get a page set of blogs and a page set of each of their comments?

  • Considering the requirements of paging, do you change the blog script of the document so that comments are not in the blog document?

+4
source share
1 answer
  • If you used .Skip() and .Take() to get a list of blog pages, you already did it right. In order to get the computed list in the comments, you can use the same methods in the list in memory (then it will be linq-to-objects). Therefore, I suggest changing your Comment[] array to List<Comment> , then you have two linq methods available.

  • If I changed the mail document so that it did not contain comments, I would not do it because of paging (there is no shortage, see my first paragraph), but because of the saved bandwidth in the database, a request. I would have 2 documents, one of which would contain a post containing all the comments. That way, you don’t have to download all the comments every time you want to display a list of posts, but still have an edge in the database when you really need them. Using RavenDB, it is also very easy to define indexes in your comments if you need them elsewhere (sidebar or so). You can find exactly this implementation in RaccoonBlog .

+3
source

Source: https://habr.com/ru/post/1390566/


All Articles