[SERVER-2157] mongoexport fails with: 10311 Number nan cannot be represented in JSON Created: 29/Nov/10  Updated: 12/Jul/16  Resolved: 03/Dec/11

Status: Closed
Project: Core Server
Component/s: JavaScript, Tools
Affects Version/s: None
Fix Version/s: 2.1.0

Type: Improvement Priority: Minor - P4
Reporter: Matthew Rathbone Assignee: Brandon Diamond
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

osx, mongo_export, macbook pro


Issue Links:
Depends
Participants:

 Description   

Exporting to JSON using mongoexport any record that contains a float which has value NaN will fail.

Simple Example:

{
"slatlng" : [NaN, NaN]
}

Additionally:

When in the mongo console, you can exclude such records using:

"slatlng" : {$ne [NaN, NaN]}

but mongoexport cannot parse this as a valid json query. So you cannot do it.



 Comments   
Comment by auto [ 03/Dec/11 ]

Author:

{u'login': u'dwight', u'name': u'dwight', u'email': u'dwight@10gen.com'}

Message: buildbot tojson NaN SERVER-2157
Branch: master
https://github.com/mongodb/mongo/commit/a094d5ff9169043cce5bba3a9270a8585443bcbd

Comment by auto [ 02/Dec/11 ]

Author:

{u'login': u'', u'name': u'Brandon Diamond', u'email': u'brandon@10gen.com'}

Message: SERVER-2157: test for NaN support
Branch: master
https://github.com/mongodb/mongo/commit/1836bcd19b7039fe9e5bb8ab77a583e83c6c8bc6

Comment by auto [ 02/Dec/11 ]

Author:

{u'login': u'', u'name': u'Brandon Diamond', u'email': u'brandon@10gen.com'}

Message: SERVER-2157: can now import/export NaN fields
Branch: master
https://github.com/mongodb/mongo/commit/c41841daa377747524a6050fa35fabd83c8f37e9

Comment by Eliot Horowitz (Inactive) [ 30/Nov/10 ]

Not really.

I would recommend writing your own json exportor.

Easy to do in any language.

Comment by Van Nguyen (vnguyen) [ 30/Nov/10 ]

I'm getting the error but I'm not sure where the NaN is, it could be anywhere among the 200k documents and their subdocs. Is there a temp solution you could recommend for that situation?

Comment by Eliot Horowitz (Inactive) [ 30/Nov/10 ]

Do you have NaN all over? If so - the type query probably won't work.
If its just a single field or array, it will work.

Comment by Van Nguyen (vnguyen) [ 30/Nov/10 ]

is there an example of how to exclude $type:6 from every field and subfield?

Comment by Eliot Horowitz (Inactive) [ 30/Nov/10 ]

Scott's suggestion should work temporarily.

The other option is of course just writing your own json exporter.

We'll need to figure out a long term solution.

Comment by Scott Hernandez (Inactive) [ 29/Nov/10 ]

You should be able to exclude $type:6 (undefined) data. Or better yet, just export $type:1 (double).

Comment by Matthew Rathbone [ 29/Nov/10 ]

Ok, so to elaborate a little more:

We're storing values with NaN for some reason (probably stored by the ORM we're using).

Ideally I'd like mongoexport to succeed and replace the NaN with something else (undefined, null, false, "NaN", anything really). Maybe it should even skip the record. My real problem is that it causes mongoexport to crash and stop exporting.

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