2

我的代码是:

using (var session = documentStore.OpenSession(databaseName))
{
    var list = session.Query<dynamic>("Raven/DocumentsByEntityName").ToArray();

    foreach (var item in list)
    {
        Console.WriteLine(item);
    }
}

但它没有给我文件的名称。我想列出单个数据库中的所有文档。

4

2 回答 2

2

试试这样的东西,它更通用一点,它允许访问原始文档

using (var session = store.OpenSession())
{
    //Issue a dummy query to make sure the indexing has finished
    var dummyQuery = session.Query<dynamic>("Raven/DocumentsByEntityName")
        .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
        .ToList();

    //First get all the document types, i.e. the different entity names
    var docTypes = store.DatabaseCommands.GetTerms("Raven/DocumentsByEntityName", "Tag", "", 128);
    foreach (var type in docTypes)
    {
        Console.WriteLine("\n{0}:", type);
        //Might need to do paging here, can only get at most 1024 docs in 1 go!
        var docs = store.DatabaseCommands.StartsWith(type, 0, 1024).ToList();

    foreach (var doc in docs)
    {
        Console.WriteLine("    {0}: {1}", doc.Key, doc.ToJson());
    }
}

}

于 2012-04-26T13:41:03.213 回答
0

为指定的数据库修改 Matt Waren 的代码。

 public void DocumentNamesWithMetadata(string databaseName="1")
        {
            using (var session = documentStore.OpenSession(databaseName))
            {
                //Issue a dummy query to make sure the indexing has finished 
                var dummyQuery = session.Query<dynamic>("Raven/DocumentsByEntityName")
                                        .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                                        .ToList();

                //First get all the document types, i.e. the different entity names 
                var docTypes = session.Advanced.DatabaseCommands.GetTerms("Raven/DocumentsByEntityName", "Tag", "", 128);
                foreach (var type in docTypes)
                {
                    Console.WriteLine("\n{0}:", type);
                    //Might need to do paging here, can only get at most 1024 docs in 1 go! 
                    var docs = session.Advanced.DatabaseCommands.StartsWith(type, 0, 1024).ToList();

                    foreach (var doc in docs)
                    {
                        Console.WriteLine("    {0}: {1}", doc.Key, doc.ToJson());
                    }
                }
            }
        }
于 2012-04-27T05:03:52.563 回答