Skip to content
Advertisement

how to find $avg and $sum for fields which contain NaN value in mongodb?

I can find and limit columns which contain NaN value before using $group clause in mongodb when I use mongo cli or JavaScript. However, when I use python and its major library “pymongo” it seems not to be able to do the same. As following code NaN is not part of python syntax. Whereas it is easy and straight forward in javaScript. Any body has same problem?

javascript

JavaScript

python (pymongo)

JavaScript

sample document of data_pool collection is like this:

JavaScript

Advertisement

Answer

A NaN value in MongoDB is represented by float('NaN') in pymongo, so you can use:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement