Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to edit meta data or otherwise modify GridFS entries without re-uploading #332

Closed
jacqueswaller opened this issue Jan 24, 2017 · 4 comments

Comments

@jacqueswaller
Copy link

A simple use case we have for this is where a user uploads an avatar image but it requires moderator approval before it can be used, and we have a tool that does a simple ['$set' => ["metadata.approved" => true/false]]. To locally work around this, I've simply added an updateOne method to MongoDB\GridFS\Bucket and MongoDB\GridFS\CollectionWrapper to let us do arbitrary updates.

I don't really have a recommendation on what the official interface for this would be, as it seems you've intended for a limited number of ways to manipulate a GridFS entry but at the same time I don't think a straight up "setMetadata" would be sufficient, as I may want to conditionally update a single property etc. etc.

@jmikola
Copy link
Member

jmikola commented Jan 24, 2017

MongoDB\GridFS\CollectionWrapper is an internal class, so it's a moot point to discuss any API modifications there.

As for MongoDB\GridFS\Bucket, the challenge with introducing a generic updateOne() method to operate on documents within fs.files (assuming the default bucket name) is that users may end up modifying fields outside of the metadata embedded document. Users can certainly create a Collection object on that namespace and do whatever they like to documents therein, but I'm hesitant to introduce this API on the Bucket itself.

Would a helper method on the Bucket suffice? For example:

public function getFilesCollection()
{
    // TODO: create $collectionOptions similarly to how we do in the Bucket constructor
    return new Collection($this->manager, $this->databaseName, $this->bucketName . '.files', $collectionOptions);
}

@jacqueswaller
Copy link
Author

Yeah that'd be fine. It's six of one half a dozen of the other, really.

@jmikola
Copy link
Member

jmikola commented Jan 25, 2017

I opened PHPLIB-258 to track the addition of accessor methods for the files and chunks collections. The feature is slated for 1.2.0. Feel free to follow that issue for updates.

@jmikola
Copy link
Member

jmikola commented Sep 15, 2017

Accessor methods have been implemented in #407, which will make it into the upcoming 1.2.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants