Reputation: 9868
I have a file saved on GridFS, via mongofiles
$ mongofiles -d dba put file.txt
connected to: 127.0.0.1
added file: { _id: ObjectId('50c0a48f8d1d53325a7d7b01'), filename: "file.txt", chunkSize: 262144, uploadDate: new Date(1354802319244), md5: "a6039c33d297d12d0dfb9b1a99bda542", length: 3527 }
done!
$ mongofiles -d dba list
connected to: 127.0.0.1
file.txt 3527
I have a model for Django & mongoengine that is defined as
class IFile(Document):
iptr = FileField(required=True)
How can I save from mongodb shell this file inside an instance of IFile?
db.ifile.save({"iptr" : ??})
Thanks
Upvotes: 0
Views: 1353
Reputation: 1620
Internally GridFS uses two collections to store data:
Documents in the files collection require the following fields:
{ "_id" : , // unique ID for this file "length" : data_number, // size of the file in bytes "chunkSize" : data_number, // size of each of the chunks. Default is 256k "uploadDate" : data_date, // date when object first stored "md5" : data_string // result of running the "filemd5" command on this file's chunks }
The structure of documents from the chunks collection is as follows:
{ "_id" : , // object id of the chunk in the _chunks collection "files_id" : , // _id of the corresponding files collection entry "n" : chunk_number, // chunks are numbered in order, starting with 0 "data" : data_binary, // the chunk's payload as a BSON binary type }
For more detailed information, click here Related Driver docs: Python
Upvotes: 2