gridfs implementation
Hi.
Any chance to have gridfs implemented? Just to not call functions from pymongo directly
Thanks
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?
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
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?
The scenario proposed is great, really :)