• <tfoot id='D9VXV'></tfoot>

    <legend id='D9VXV'><style id='D9VXV'><dir id='D9VXV'><q id='D9VXV'></q></dir></style></legend>

    <small id='D9VXV'></small><noframes id='D9VXV'>

    • <bdo id='D9VXV'></bdo><ul id='D9VXV'></ul>
    <i id='D9VXV'><tr id='D9VXV'><dt id='D9VXV'><q id='D9VXV'><span id='D9VXV'><b id='D9VXV'><form id='D9VXV'><ins id='D9VXV'></ins><ul id='D9VXV'></ul><sub id='D9VXV'></sub></form><legend id='D9VXV'></legend><bdo id='D9VXV'><pre id='D9VXV'><center id='D9VXV'></center></pre></bdo></b><th id='D9VXV'></th></span></q></dt></tr></i><div id='D9VXV'><tfoot id='D9VXV'></tfoot><dl id='D9VXV'><fieldset id='D9VXV'></fieldset></dl></div>

      1. Flask-MongoEngine &amp;PyMongo 聚合查询

        Flask-MongoEngine amp; PyMongo Aggregation Query(Flask-MongoEngine amp;PyMongo 聚合查询)
          <legend id='xOfnC'><style id='xOfnC'><dir id='xOfnC'><q id='xOfnC'></q></dir></style></legend>

            <tfoot id='xOfnC'></tfoot>

              <tbody id='xOfnC'></tbody>
          1. <i id='xOfnC'><tr id='xOfnC'><dt id='xOfnC'><q id='xOfnC'><span id='xOfnC'><b id='xOfnC'><form id='xOfnC'><ins id='xOfnC'></ins><ul id='xOfnC'></ul><sub id='xOfnC'></sub></form><legend id='xOfnC'></legend><bdo id='xOfnC'><pre id='xOfnC'><center id='xOfnC'></center></pre></bdo></b><th id='xOfnC'></th></span></q></dt></tr></i><div id='xOfnC'><tfoot id='xOfnC'></tfoot><dl id='xOfnC'><fieldset id='xOfnC'></fieldset></dl></div>

              1. <small id='xOfnC'></small><noframes id='xOfnC'>

                  <bdo id='xOfnC'></bdo><ul id='xOfnC'></ul>
                • 本文介绍了Flask-MongoEngine &amp;PyMongo 聚合查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用flask-mongoengine 进行聚合查询,根据我的阅读,这听起来不太可能.

                  I am trying to make an aggregation query using flask-mongoengine, and from what I have read it does not sound like it is possible.

                  我查看了几个论坛主题、电子邮件链和一些关于 Stack Overflow 的问题,但我还没有找到一个很好的例子来说明如何使用 flask-mongoengine 实现聚合.

                  I have looked over several forum threads, e-mail chains and a few questions on Stack Overflow, but I have not found a really good example of how to implement aggregation with flask-mongoengine.

                  这个问题中有一条评论说你必须使用raw pymongo and聚合功能."但是,没有例子说明它是如何工作的.我已经修改了 Python 并使用 Flask 框架构建了一个基本应用程序,但我正在研究完整的应用程序和应用程序.连接/查询 Mongo 对我来说很新鲜.

                  There is a comment in this question that says you have to use "raw pymongo and aggregation functionality." However, there is no examples of how that might work. I have tinkered with Python and have a basic application up using Flask framework, but delving into full fledged applications & connecting/querying to Mongo is pretty new to me.

                  有人可以提供一个示例(或指向示例的链接),说明我可以如何利用我的 flask-mongoengine 模型,但使用 PyMongo 的聚合框架进行查询?这是否需要两个到 MongoDB 的连接(一个用于 PyMongo 执行聚合查询,另一个用于通过 MongoEngine 进行常规查询/插入/更新)?

                  Can someone provide an example (or link to an example) of how I might utilize my flask-mongoengine models, but query using the aggregation framework with PyMongo? Will this require two connections to MongoDB (one for PyMongo to perform the aggregation query, and a second for the regular query/insert/updating via MongoEngine)?

                  我想要执行的聚合查询示例如下(这个查询让我得到了我在 Mongo shell 中想要的信息):

                  An example of the aggregation query I would like to perform is as follows (this query gets me exactly the information I want in the Mongo shell):

                  db.entry.aggregate([
                      { '$group' : 
                          { '_id' : { 'carrier' : '$carrierA', 'category' : '$category' }, 
                            'count' : { '$sum' : 1 }
                          }
                      }
                  ])
                  

                  此查询的输出示例:

                  { "_id" : { "carrier" : "Carrier 1", "category" : "XYZ" }, "count" : 2 }
                  { "_id" : { "carrier" : "Carrier 1", "category" : "ABC" }, "count" : 4 }
                  { "_id" : { "carrier" : "Carrier 2", "category" : "XYZ" }, "count" : 31 }
                  { "_id" : { "carrier" : "Carrier 2", "category" : "ABC" }, "count" : 6 }
                  

                  推荐答案

                  你用 Mongoengine 定义的类实际上有一个 _get_collection() 方法,它获取在 pymongo 中实现的原始"集合对象司机.

                  The class your define with Mongoengine actually has a _get_collection() method which gets the "raw" collection object as implemented in the pymongo driver.

                  我只是在这里使用名称 Model 作为此示例中为连接定义的实际类的占位符:

                  I'm just using the name Model here as a placeholder for your actual class defined for the connection in this example:

                  Model._get_collection().aggregate([
                      { '$group' : 
                          { '_id' : { 'carrier' : '$carrierA', 'category' : '$category' }, 
                            'count' : { '$sum' : 1 }
                          }
                      }
                  ])
                  

                  因此,您始终可以访问 pymongo 对象,而无需建立单独的连接.Mongoengine 本身是基于 pymongo 构建的.

                  So you can always access the pymongo objects without establishing a separate connection. Mongoengine is itself build upon pymongo.

                  这篇关于Flask-MongoEngine &amp;PyMongo 聚合查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <tfoot id='TVp7N'></tfoot>
                • <small id='TVp7N'></small><noframes id='TVp7N'>

                  <legend id='TVp7N'><style id='TVp7N'><dir id='TVp7N'><q id='TVp7N'></q></dir></style></legend>
                  <i id='TVp7N'><tr id='TVp7N'><dt id='TVp7N'><q id='TVp7N'><span id='TVp7N'><b id='TVp7N'><form id='TVp7N'><ins id='TVp7N'></ins><ul id='TVp7N'></ul><sub id='TVp7N'></sub></form><legend id='TVp7N'></legend><bdo id='TVp7N'><pre id='TVp7N'><center id='TVp7N'></center></pre></bdo></b><th id='TVp7N'></th></span></q></dt></tr></i><div id='TVp7N'><tfoot id='TVp7N'></tfoot><dl id='TVp7N'><fieldset id='TVp7N'></fieldset></dl></div>
                  • <bdo id='TVp7N'></bdo><ul id='TVp7N'></ul>

                              <tbody id='TVp7N'></tbody>