Skip to main content

Commands: Documents: Stream

StreamDocs is used to stream documents which match chosen criteria from a database.

Syntax

IEnumerator<RavenJObject> StreamDocs(
Etag fromEtag = null,
string startsWith = null,
string matches = null,
int start = 0,
int pageSize = int.MaxValue,
string exclude = null,
RavenPagingInformation pagingInformation = null,
string skipAfter = null,
string transformer = null,
Dictionary<string, RavenJToken> transformerParameters = null);
Parameters
fromEtagEtagETag of a document from which stream should start (mutually exclusive with 'startsWith')
startsWithstringprefix for which documents should be streamed (mutually exclusive with 'fromEtag')
matchesstringpipe ('|') separated values for which document keys (after 'keyPrefix') should be matched ('?' any single character, '*' any characters)
startintnumber of documents that should be skipped
pageSizeintmaximum number of documents that will be retrieved
excludeintpipe ('|') separated values for which document keys (after 'keyPrefix') should not be matched ('?' any single character, '*' any characters)
pagingInformationRavenPagingInformationused to perform rapid pagination on a server side
skipAfterStringskip document fetching until given key is found and return documents after that key (default: null)
transformerStringname of transformer (default: null)
transformerParametersDictionary<string, RavenJToken>parameters to pass to the transformer (default: null)

Example 1

IEnumerator<RavenJObject> enumerator = store.DatabaseCommands.StreamDocs(null, "products/");
while (enumerator.MoveNext())
{
RavenJObject document = enumerator.Current;
}

Example 2

Using the following transformer:

private class SimpleTransformer : AbstractTransformerCreationTask
{
public class Result
{
public string Name { get; set; }
}

public override TransformerDefinition CreateTransformerDefinition(bool prettify = true)
{
return new TransformerDefinition
{
Name = "SimpleTransformer",
TransformResults = "from r in results select new { Name = Parameter(\"Name\") }"
};
}
}

StreamDocs using the SimpleTransformer defined above and one supplied parameter:

var transformer = new SimpleTransformer();
transformer.Execute(store);

using (IEnumerator<RavenJObject> enumerator = store.DatabaseCommands.StreamDocs(startsWith: "people/", transformer: transformer.TransformerName, transformerParameters: new Dictionary<string, RavenJToken> {{"Name", "Bill"}}))
{
while (enumerator.MoveNext())
{
RavenJObject result = enumerator.Current;
string name = result.Value<string>("Name");
Assert.Equal("Bill", name); // Should be true
}
}