0

我通过 mongofiles 在 GridFS 上保存了一个文件

$ 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

我有一个 Django 和 mongoengine 的模型,定义为

class IFile(Document):
    iptr = FileField(required=True)

如何从 mongodb shell 将此文件保存在 IFile 的实例中?

db.ifile.save({"iptr" : ??})

谢谢

4

1 回答 1

2

Internally GridFS uses two collections to store data:

  • fs.files contains the object metadata
  • fs.chunks contains the binary chunks with some additional accounting information

Files

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
}

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

于 2012-12-09T16:12:46.023 回答