Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDB. How to load document with only 5 items from inner collection?

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" }
     ]
}
like image 429
Dmitry Schetnikovich Avatar asked Jul 31 '10 18:07

Dmitry Schetnikovich


1 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 }

You can then query the index for the first five employees

like image 185
Ayende Rahien Avatar answered Oct 18 '22 06:10

Ayende Rahien