Reputation: 14205
I'm using the RavenDB streaming API to retrieve all 355,000 DocsToProcess
from my database instance using the following code:
_myDocs = new List<DocsToProcess>();
var query = RavenSession.Query<DocsToProcess>();
using (var enumerator = RavenSession.Advanced.Stream(query))
{
while (enumerator.MoveNext())
{
DocsToProcess u = enumerator.Current.Document;
_myDocs.Add(u);
}
}
However, the following exception message is thrown:
StreamQuery does not support querying dynamic indexes. It is designed to be used with large data-sets and is unlikely to return all data-set after 15 sec of indexing, like Query() does.
How I can correctly iterate through all elements of type DocsToProcess
in my C# application?
Upvotes: 0
Views: 950
Reputation: 904
Similar to JHo above, the solution that I came up with means that you do not need to make a static index for streaming, because you're relying on the default index and using the StartsWith
overload of Stream<T>
in the Raven client.
We've found the solution below to work fine for most of our use-cases where we need to get everything from a Raven instance.
public IEnumerable<T> GetAll()
{
var results = new List<T>();
var conventions = _documentStore.Conventions ?? new DocumentConvention();
var defaultIndexStartsWith = conventions.GetTypeTagName(typeof(T));
using(var session = _documentStore.OpenSession())
{
using(var enumerator = session.Advanced.Stream<T>(defaultIndexStartsWith))
{
while(enumerator.MoveNext())
results.Add(enumerator.Current.Document);
}
}
return results;
}
Upvotes: 1
Reputation: 466
To get by without creating a static index, you can provide some minimal bounding like this:
using (var session = store.OpenSession())
{
IEnumerator<StreamResult<Employee>> stream =
session.Advanced.Stream<Employee>("employees/");
while (stream.MoveNext())
{
// ....
}
}
Upvotes: 0
Reputation: 5078
The documentation says explicitly for unbound results:
Important side notes:
- the index already exists. Creation of a index won't occur and the query error with an IndexDoesNotExistsException exception.
And that's what your exception is saying. You have to create a static index for streaming results.
Upvotes: 3