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

指定されたデータベースのMattwarenのコードを変更します。

 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 に答える