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
fromEtag Etag ETag of a document from which stream should start (mutually exclusive with 'startsWith')
startsWith string prefix for which documents should be streamed (mutually exclusive with 'fromEtag')
matches string pipe ('|') separated values for which document keys (after 'keyPrefix') should be matched ('?' any single character, '*' any characters)
start int number of documents that should be skipped
pageSize int maximum number of documents that will be retrieved
exclude int pipe ('|') separated values for which document keys (after 'keyPrefix') should not be matched ('?' any single character, '*' any characters)
pagingInformation RavenPagingInformation used to perform rapid pagination on a server side
skipAfter String skip document fetching until given key is found and return documents after that key (default: null)
transformer String name of transformer (default: null)
transformerParameters Dictionary<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
    }
}