RavenDB. How to download a document of only 5 items from the internal collection?

Here is the document in the store:

{
    "Name": "Hibernating Rhinos", 
    "Employees": [
        { "Name": "Ayende" },
        { "Name": "John" },
        { "Name": "Bob" },
        { "Name": "Tom" },
        { "Name": "Lane" },
        { "Name": "Bill" },
        { "Name": "Tad" }
     ]
}

It’s easy to download this document with or without the Employees collection , but how can I download only part of the internal collection? For example, the first 5 elements:

{
    "Name": "Hibernating Rhinos", 
    "Employees": [
        { "Name": "Ayende" },
        { "Name": "John" },
        { "Name": "Bob" },
        { "Name": "Tom" },
        { "Name": "Lane" }
     ]
}
+5
source share
2 answers

Not directly, not.

What you can do is define the following index:

from company in docs.Companies
from emp in company.Employees
select new {Compnany = company.Name, Employee = emp}

Then you can request an index for the first five employees

+6
source

Live Projections RavenDB. TransformResults : , - Company.

TransformResults = (database, companies) => from c in companies
                                        select new {Company=c,Employees=c.Employees.Take(5)};
0

All Articles