我在 mongodb.I 中有一个数据集想要执行一些在 python.How 中编码的功能我是否在其上执行这些功能(i.e.bar 给定数据的图表)

I have a dataset in mongodb.I want to perform some functions coded in python.How do I perform those functions on it(i.e.bar graph of the given data)

use indbar1
db.branch.insert({ "name" : "b1" , "y2000" : 80 , "y2001" : 105 })

以上是数据库和集合名称的剪辑以及数据类型的外观

您可以尝试以下聚合查询:

db.collection.aggregate([
  /** Match docs where both fields exists */
  {
    $match: {
      "y2000": {
        $exists: true
      },
      "y2001": {
        $exists: true
      }
    }
  },
  /** Group branches & sum up each fields values across all docs */
  {
    $group: {
      _id: "$name",
      y2000: {
        $sum: "$y2000"
      },
      y2001: {
        $sum: "$y2001"
      }
    }
  },
  /** Transform fields to required format */
  {
    $project: {
      _id: 0,
      x: "$_id",
      y2000: 1,
      y2001: 1
    }
  }
])

测试: MongoDB-Playground