我正在try 使用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’对象没有‘DATABASE_COMMANDS’属性

显然,database_commands是不可用的.但是,如何使用py-ravenb列出RavenDB V5.4+数据库中的所有集合呢?

推荐答案

我想你可以用maintenance operation GetCollectionStatisticsOperation.
它将为您提供具有属性collections的类CollectionStatistics.

Operation definition is in:
https://github.com/ravendb/ravendb-python-client/blob/b2eccad9e183c8988bb2bed808e5b3807c8a4081/ravendb/documents/operations/statistics.py#L63

A sample code that calls a maintenance operation can be found here:
https://github.com/ravendb/ravendb-python-client/blob/b2eccad9e183c8988bb2bed808e5b3807c8a4081/ravendb/tests/operations_tests/test_maintenance_operations.py#L19

注意:该示例演示如何发送另一个操作,
但是...遵循它,并使用类似以下内容:

self.store.maintenance.send(GetCollectionStatisticsOperation())

它应该返回在您的store 中定义的stats about the default database.
其中一个统计props 是Collections

Python相关问答推荐

在Google Colab中设置Llama-2出现问题-加载判断点碎片时Cell-run失败

如何访问所有文件,例如环境变量

在Wayland上使用setCellWidget时,try 编辑QTable Widget中的单元格时,PyQt 6崩溃

如何在给定的条件下使numpy数组的计算速度最快?

pyscript中的压痕问题

Python—从np.array中 Select 复杂的列子集

对象的`__call__`方法的setattr在Python中不起作用'

什么是最好的方法来切割一个相框到一个面具的第一个实例?

多处理队列在与Forking http.server一起使用时随机跳过项目

如何并行化/加速并行numba代码?

什么是合并两个embrame的最佳方法,其中一个有日期范围,另一个有日期没有任何共享列?

如何排除prefecture_related中查询集为空的实例?

使用类型提示进行类型转换

计算机找不到已安装的库'

504未连接IB API TWS错误—即使API连接显示已接受''

Django.core.exceptions.SynchronousOnlyOperation您不能从异步上下文中调用它-请使用线程或SYNC_TO_ASYNC

查找查找表中存在的列值组合

如何将列表从a迭代到z-以抓取数据并将其转换为DataFrame?

具有不同坐标的tkinter canvs.cocords()和canvs.moveto()

401使用有效的OAuth令牌向Google Apps脚本Web App发出POST请求时出现未经授权的错误(";