5

Here is a document in the store:

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

It is easy to load this document with or without Employees collection, but how to load only part of inner collection? For instance, first 5 items:

{
    "Name": "Hibernating Rhinos", 
    "Employees": [
        { "Name": "Ayende" },
        { "Name": "John" },
        { "Name": "Bob" },
        { "Name": "Tom" },
        { "Name": "Lane" }
     ]
}
Dmitry Schetnikovich
  • 1,752
  • 17
  • 26

2 Answers2

6

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 }

You can then query the index for the first five employees

Mike Scott
  • 12,274
  • 8
  • 40
  • 53
Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
0

You can use Live Projections feature of RavenDB. Put this query in TransformResults function of your index: I assume that your document name is Company.

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