[SERVER-27422] Agg Pipeline return none type on from AVG func - is it working differently in 3.08 v 3.2.11 Created: 14/Dec/16  Updated: 27/Oct/23  Resolved: 14/Dec/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Richard Bowyer Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

3.2.11


Attachments: File slocIntToHour.py    
Issue Links:
Duplicate
is duplicated by SERVER-27423 CLONE - Agg Pipeline return none type... Closed
Related
related to SERVER-14691 $avg aggregation operator should retu... Closed
Participants:

 Description   

Same exact code run from Python IDE and same data (copy) in Mongo 3.08 v 3.2.11 is yielding different results. The agg pipeline has an AVG function and the results are feed into a round function. When I run v. the upgraded database (same exact python code), I get none type from the agg pipeline. When I run v. legacy, I don't -> I get float types.



 Comments   
Comment by Kelsey Schubert [ 14/Dec/16 ]

Hi bowyerr,

As Bernie described, this is the expected behavior resulting from the change in SERVER-14691. In MongoDB 3.2, if all values are are missing, null, or non-numeric, the $avg will return null instead of 0. Please take a look at the test cases that were introduced in commit under SERVER-14691 for examples of this behavior

We understand that this was a backwards breaking change, but believe that the improvements were worthwhile. Previously, you could not determine if an average was 0 because there were nonnumeric fields or because the the numeric average of the fields was 0.

If you are seeing null values being returned to your application, and would like to be seeing 0 instead, please append the following stage following the $avg stage in your aggregation where average the field containing your commuted average:

{
	$project: {
	            average: { $ifNull: [ "$average", 0 ] }
	}
}

This workaround should restore the previous behavior.

Kind regards,
Thomas

Comment by Richard Bowyer [ 14/Dec/16 ]

I need to know what changed in which function(s) and the recommend remediation.

Comment by Richard Bowyer [ 14/Dec/16 ]

Wait a minute. Worked in old, but not in new. That is NOT worked as designed as a resolution. Please reopen and try again.

Comment by Bernie Hackett [ 14/Dec/16 ]

It looks like the behavior change is a result of SERVER-14691. Note that $sum was not changed.

Comment by Richard Bowyer [ 14/Dec/16 ]

File attached

Comment by Bernie Hackett [ 14/Dec/16 ]

If you can send an example agg pipeline that reproduces the problem I would be happy to debug this further with the server team. Otherwise I'll close this ticket Won't Fix, since there is no way to fix this in PyMongo.

Comment by Richard Bowyer [ 14/Dec/16 ]

Agree. I believe that this had nothing to do with Pymongo and everything to do with a change in behavior with the Agg Pipeline between the versions.

Comment by Bernie Hackett [ 14/Dec/16 ]

Hi,

Can you send an example pipeline? I doubt this has anything to do with PyMongo. It sounds like a change in server behavior between 3.0 and 3.2.

Generated at Thu Feb 08 04:15:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.