I'm using mongodb module to download a file from gridfs.
Here's the code -
import { Db, Server, GridFSBucket } from 'mongodb';
let gfs = new GridFSBucket(new Db(<db_name>, new Server("127.0.0.1", 27017)), {"bucketName": "fs"});
let readStreamData = gfs.openDownloadStream(<ObjectId>);
The output is the following error -
error occurred in downloadreport TypeError: Cannot read property 'write' of null
at Object.query (C:\project\node_modules\mongodb\lib\core\wireprotocol\query.js:29:19)
at Server.query (C:\project\node_modules\mongodb\lib\core\topologies\server.js:639:16)
at FindOperation.execute (C:\project\node_modules\mongodb\lib\operations\find.js:24:12)
at C:\project\node_modules\mongodb\lib\operations\execute_operation.js:168:15
at Server.selectServer (C:\project\node_modules\mongodb\lib\core\topologies\server.js:827:3)
at Server.selectServer (C:\project\node_modules\mongodb\lib\topologies\topology_base.js:363:32)
at executeWithServerSelection (C:\project\node_modules\mongodb\lib\operations\execute_operation.js:150:12)
at executeOperation (C:\project\node_modules\mongodb\lib\operations\execute_operation.js:81:16)
at Cursor._initializeCursor (C:\project\node_modules\mongodb\lib\core\cursor.js:545:7)
at Cursor._initializeCursor (C:\project\node_modules\mongodb\lib\cursor.js:191:11)
at nextFunction (C:\project\node_modules\mongodb\lib\core\cursor.js:748:10)
at Cursor._next (C:\project\node_modules\mongodb\lib\core\cursor.js:202:5)
at nextObject (C:\project\node_modules\mongodb\lib\operations\common_functions.js:234:10)
at NextOperation.execute (C:\project\node_modules\mongodb\lib\operations\next.js:26:5)
at executeOperation (C:\project\node_modules\mongodb\lib\operations\execute_operation.js:83:26)
at Cursor.next (C:\project\node_modules\mongodb\lib\cursor.js:217:12)
C:\project\node_modules\mongodb\lib\utils.js:133
throw err;
does anyone know what is it that I'm doing wrong?
PS: I also want to download and save the data I receive in a pdf file (the data is pdf content already). How can I achieve this?
from GridFSBucketReadStream error: cannot read property 'write' of null
No comments:
Post a Comment