【发布时间】:2020-08-01 03:35:35
【问题描述】:
我有一个在 Python 中使用 MongoDB 的跳过和限制函数的应用程序。它根据从服务器返回的内容获取数据,并且每次将跳过和限制增加 10。但是,当我尝试在我的应用程序中实现过滤机制时,过滤仅适用于我返回的这十个项目。有人可以告诉我如何检索过滤后的数据,这些数据是在需要过滤的整个数据中执行的,而不仅仅是十个项目?我需要能够以跳过和限制形式检索这些数据。在尝试实现这一目标时,我似乎无法理解。
这是我用于对上下文进行排序的示例函数
@app.route('/api/belowhundred/<country>/<skip>/<limit>',methods=['POST'])
def belowhundred(country,skip,limit):
products = db_products.find({'country':country}).skip(int(skip)).limit(int(limit))
prods = []
for product in products:
if int(product['price']) <= 100:
prods.append(product)
products = dumps(prods)
return products
【问题讨论】:
-
能否提供样本数据?
-
将过滤器放在聚合中的限制之前。
-
@Joe 我没听懂你
标签: python database mongodb pymongo