aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

Updating file metadata #98

Closed hoodsy closed 8 years ago

hoodsy commented 8 years ago

Is there an example of a file's metadata being accessed?

I've had success finding / removing files using the convenience methods gfs.files.findOne, gfs.remove etc, but querying the fs.files collection directly has been problematic.

From #82 , it seems like I should be able to use gfs.db.collection('fs.files') to access the collection, but all of my queries come up empty. I would simply like to update a single file's metadata.

Any examples / feedback would be greatly appreciated!

UajoV6 commented 8 years ago

Have you accomplished to query a collection by a subdocument inside the metadata? like for example gfs.files.find({"metadata.name":"carl"}) i can not find my way though

hoodsy commented 8 years ago

I did get it working, and here's what my query looks like:

gfs.files.update(
      { _id: gfsId },
      { $set: {
        'metadata.mediaId': mediaData.media_id_string,
        'metadata.mediaIdCreated': getTimeInSeconds(),
        'metadata.mediaIdExpires': mediaData.expires_after_secs
      } }
    )
omnidan commented 7 years ago

@hoodsy is this still working for you? I'm trying almost the exact same query (#103) and it doesn't seem to modify the metadata for me.

hoodsy commented 7 years ago

It still works for me, although it definitely felt fragile when I got it to work.

On Mon, Dec 26, 2016 at 12:15 PM, Daniel Bugl notifications@github.com wrote:

@hoodsy https://github.com/hoodsy is this still working for you? I'm trying almost the exact same query (#103 https://github.com/aheckmann/gridfs-stream/issues/103) and it doesn't seem to modify the metadata for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aheckmann/gridfs-stream/issues/98#issuecomment-269228136, or mute the thread https://github.com/notifications/unsubscribe-auth/AEQruvKDd_vNPeN7XOVBh1TDFDf4FB3Tks5rL_ZLgaJpZM4Jus6_ .

omnidan commented 7 years ago

@hoodsy which gridfs-stream and mongod version are you using?

carlosbbraga commented 5 years ago

Is this working ?? I can only get it working by using filename on where instead of _id. Ex: gfs.files.update( { filename: 'carlos2.png' }, { $set: { 'metadata.somedata': 'teste' } }