为指定的数据库修改 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());
}
}
}
}