Closed toconnell closed 8 months ago
Rewrote the world/init.py get_top
method to use a pipeline and remove some ugly post-query sorting:
- results = utils.mdb[collection].group(
- [attrib], query, {"count": 0}, "function(o, p){p.count++}"
- )
+# results = utils.mdb[collection].group(
+# [attrib], query, {"count": 0}, "function(o, p){p.count++}"
+# )
+
+ pipeline = [
+ {
+ '$match': query # Add a $match stage if necessary based on your existing 'query'
+ },
+ {
+ '$group': {
+ '_id': '$' + attrib, # Group by the 'attrib' field
+ 'count': {'$sum': 1} # Increment count for each group
+ }
+ },
+ {
+ '$sort': {'count': -1} # Sort by 'count' field in descending order
+ }
+ ]
+
+ sorted_list = list(utils.mdb[collection].aggregate(pipeline))
+ if self.query_debug:
+ self.logger.debug('MDB results: %s', sorted_list)
- sorted_list = sorted(results, key=lambda k: k["count"], reverse=True)
- for i in sorted_list:
- i["value"] = i[attrib]
- i["count"] = int(i["count"])
+# sorted_list = sorted(results, key=lambda k: k["count"], reverse=True)
+# for i in sorted_list:
+# i["value"] = i[attrib]
+# i["count"] = int(i["count"])
Methods to validate:
Validations look good; all assets refresh. This is resolved.
The first world run versus the new MongoDB threw a bunch of errors: