How to return _id after upload file with GridFS?

Hey all,

I’m trying to build a relatively basic imageboard. I’m using GridFS to upload an image, but I’m trying to create a comments section for each image. What I’m trying to do is create a new entry in a mongoDB store (ie. CommentDB), and I want to tie that document to the _id of the image that was uploaded, so I figure do something like:

myId = this._id;
CommentDB.insert({photoID: myId});

then I would update that document with comments every time a user comments on it.
So how do I do this? I figured that after the image is uploaded, somehow get the _id returned, but I can’t find any documentation that explains how to get it returned.

Any help would be great

  Images.insert(data, function(err, fileObj){
    } else {
      Session.set("photoURL", fileObj._id);

I’m guessing use the fileObj in callback?

1 Like

Yes that was it lol
I had actually figured it out after I posted this, i just had to test that callback in the console then i found it out