我正在尝试使用 RavenDB's Python Client 查询或列出 RavenDB 数据库中的所有集合.
到目前为止,我已经得到了类似的结果:
URLS = ['http://localhost:8080']
DB_NAME = 'my-db'
store = DocumentStore(URLS, DB_NAME)
store.initialize()
with store.open_session() as session:
collections = session.advanced.document_store.database_commands.get_collections(0, 50)
最后一行错误:
AttributeError: 'DocumentStore' object has no attribute 'database_commands'
显然database_commands
不可用。但是如何使用 py-ravendb 列出 RavenDB v5.4+ 数据库中的所有集合?
最佳答案
我认为您可以使用维护操作 GetCollectionStatisticsOperation
。
它将为您提供具有属性 collections
的类 CollectionStatistics
。
可以在此处找到调用维护操作的示例代码:
https://github.com/ravendb/ravendb-python-client/blob/b2eccad9e183c8988bb2bed808e5b3807c8a4081/ravendb/tests/operations_tests/test_maintenance_operations.py#L19
注意:该示例演示了发送另一个操作,
但是...遵循它并使用类似的东西:
self.store.maintenance.send(GetCollectionStatisticsOperation())
它应该返回您商店中定义的有关默认数据库的统计信息。
统计 Prop 之一是 Collections
关于python - 使用 py-ravendb 列出 RavenDB 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74852776/