python - MongoDB shell 的 db.stats() 在 php 和 python 中

标签 python php mongodb pymongo mongodb-php

我可以从 Mongo shell 中看到统计数据

db.stats()

db.collection_name.stats()

如何从 PHP 和 Python 查看数据库或集合的统计信息。

编辑: 我已经用 PHP 完成了,但仍然不能用 Python 完成。

帮忙吗?

最佳答案

如果您使用 PyMongo 驱动程序,这就是您在 Python 中执行此操作的方法:


connection = pymongo.Connection(host = "127.0.0.1", port = 27017)
db = connection["test_db"]
test_collection = db["test_collection"]
db.command("dbstats") # prints database stats for "test_db"
db.command("collstats", "test_collection") # prints collection-level stats for "test_collection" under "test_db".  

引用资料:

  • db.command()
  • MongoDB: how to get db.stats() from API
  • 关于python - MongoDB shell 的 db.stats() 在 php 和 python 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11648627/

    相关文章:

    python - 在 Python 中以 1000 秒为单位测量两个经纬度点之间的距离

    python - 如何在 Pandas DataFrame 中记录 "least occuring"项目?

    PHP 加载 MySQL 时出错

    PHP变量替换

    mongodb - 将字符串日期转换为 MongoDB 中的日期

    python - 基本并行化。创建一个工作人员池,所有工作人员并行运行相同的功能

    python - 对象没有属性 'build_absolute_uri' - Django Rest Framework

    php - 谁能在这行 php 代码中找到 undefined index 吗?

    ruby-on-rails - Mongoid embeds_many 和 has_many 到同一个模型

    javascript - 使用聚合管道聚合 MongoDB 中的时间戳集合