Project

Profile

Help

Issue #3018

closed

mongo 3.4 warning over the use of aggregates

Added by mihai.ibanescu@gmail.com over 6 years ago. Updated almost 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
1. Low
Version:
2.10.3
Platform Release:
2.14.1
OS:
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
Easy Fix, Pulp 2
Sprint:
Quarter:

Description

After moving to Mongo 3.4, we started seeing these warnings in the Mongo logs:

########################
2017-08-21T07:03:34.521-0400 W COMMAND [conn330]

Use of the aggregate command without the 'cursor' option is deprecated. See http://dochub.mongodb.org/core/aggregate-without-cursor-deprecation.

We have isolated the problem, and here is the proposed fix:

--- pulp/server/controllers/repository.py.orig    2017-09-15 11:15:16.915548622 -0400
+++ pulp/server/controllers/repository.py    2017-09-15 11:22:25.754073661 -0400
@@ -301,11 +301,11 @@
     pipeline = [
         {'$match': {'repo_id': repository.repo_id}},
         {'$group': {'_id': '$unit_type_id', 'sum': {'$sum': 1}}}]
-    q = db.command('aggregate', 'repo_content_units', pipeline=pipeline)
+    q = db.repo_content_units.aggregate(pipeline=pipeline)

     # Flip this into the form that we need
     counts = {}
-    for result in q['result']:
+    for result in q:
         counts[result['_id']] = result['sum']

     repository.content_unit_counts = counts

I believe pymongo is setting useCursor=True when dealing with aggregates in a collection, but not if invoked as a command.

Also available in: Atom PDF