0

I am trying to get back the _id of a document that has been streamed to MongoDB via GridFS. Is there a way to do this?

The code is very simple. I am running the following to insert the document into MongoDB:

readableStream.pipe(bucket.openUploadStream('myFile.pdf');

Looking for a way to get the _id back from this stream - if anyone knows a way to do this please advise.

Robert
  • 176
  • 1
  • 12

1 Answers1

0

We can listen to the finish event of bucket upload stream

const uploadStream = bucket.openUploadStream('myFile.pdf');

uploadStream.on("finish", (file) => {
  console.log(file); // data here
});

readableStream.pipe(uploadStream);
hungtran273
  • 1,180
  • 9
  • 11