Download a mongo model with NodeJS

0

I have a Mongo database and I would like, through an API in Node, to be able to download these records in zip, in a CSV or whatever format. Right now I have 501426 records so the find of the model gives me the following error when getting all the records:

<--- Last few GCs --->

[15092:000001FE5E775B70]    95966 ms: Mark-sweep 1407.6 (1467.7) -> 1407.5 
(1451.2) MB, 1408.9 / 0.0 ms  last resort GC in old space requested
[15092:000001FE5E775B70]    97421 ms: Mark-sweep 1407.5 (1451.2) -> 1407.5 
(1451.2) MB, 1454.2 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 000003F5F89A5EE1 <JSObject>
2: GetHash(aka GetHash) [native collection.js:1] [bytecode=000003F5F89D1721 
offset=51](this=0000011364082311 <undefined>,o=000002F6E28FAE89 <JSFunction  
wrapper (sfi = 000003167E337821)>)
4: set [native weak-collection.js:1] [bytecode=000003167E3380F9 offset=50]
(this=000001DB08591699 <JSWeakMap>,key=000002F6E28FAE89 <JSFunction wrapper 
(sfi = 000003167E337821)>,value=00000021B54F67F9 <J...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of 
memory

I understand that there are many records and you are not able to process all of them, but would there be any way? Thank you!

    
asked by oihi08 15.01.2018 в 16:40
source

1 answer

0

Try sending the data streaming from mongodb:

collection 
    .find() 
    .stream() 
    .pipe(res)

More info: link

    
answered by 16.01.2018 в 00:14