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

gridfs implementation #10

Open
njordr opened this issue Aug 29, 2016 · 4 comments
Open

gridfs implementation #10

njordr opened this issue Aug 29, 2016 · 4 comments

Comments

@njordr
Copy link

njordr commented Aug 29, 2016

Hi.

Any chance to have gridfs implemented? Just to not call functions from pymongo directly

Thanks

@anthonyjb
Copy link
Member

Hi @njordr,

I'm afraid I've limited experience with GridFS having only used on one project and that was using MongoEngine. They provide a FileField class which makes it simple to stored/retrieve/manage a file against an attribute. Given that MongoFrames doesn't implement a type schema for collection/frame fields we'd need to have a think about how best to simplify the interface to GridFS.

Do you have any thoughts or an example snippet of pseudo code on what the interface for GridFS should look like in MongoFrames?

@njordr
Copy link
Author

njordr commented Aug 30, 2016

I wondering if gridfs could be managed as a SubFrame, so when a field is a gridfs element it could be implemented as a SubFrame class (GridFrame class? :) )
In this way it is possible to hide all the operations of insert, delete, and so on

@anthonyjb
Copy link
Member

Beyond the Id of the file what else would the SubFrame/Embedded document store, if it's just the Id this seems like we'd be creating structure for a single field?

One option I thought might be viable be is to look for a special postfix to attribute names, for example:

from mongoframes import Frame

class Product(Frame):

    _fields = {
        'sku',
        'name',
        'desc',
        'price',
        'images',
        'manual'
        }

product = Product(
    sku='A123',
    name='Mouse',
    desc='Squeaks a lot',
    price=500
    )

# Store a single file using GridFS
with open('mouses_are_great.pdf') as f:
    product.manual_fs.put(f.read())

# Store multiple files using GridFS
pics = []
for pic in ['mouse_posing', 'mouse_scoffing_cheese', 'mouse_trapped']
    with open(pic + '.jpg') as f:
        pics.append(f.read())

product.images_fs.put_many(pics)

# Save the product
product.insert()

# Retrieve the manual
manual = product.manual_fs.get()

# Retrieve the images
images = product.manual_fs.get_many()

In this scenario only the Id of the file is saved, by default this would use the same database to store the GridFS files as the Frame uses to store it's data, we'd need to figure out a way to make this easy to override - but before I look at that further what are your thoughts on this?

@njordr
Copy link
Author

njordr commented Sep 2, 2016

The scenario proposed is great, really :)

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

No branches or pull requests

2 participants