Custom field in GridFS

1.6k Views Asked by At

its possible save custom field in GridFS, im using NodeJS and gridfs-stream module. The file is saved as next schema:

{
_id: "5208b9929e462bc24b000001",
filename: "algo.txt",
contentType: "binary/octet-stream",
length: 133074,
chunkSize: 262144,
uploadDate: "2013-08-12T10:31:46.152Z",
aliases: null,
metadata: null,
md5: "56cd6b2057623bfb70111b883678d436"
}

Its possible add custom field with user id that uploaded the file. Other possibility can be put in metadata... but later for find its expensive.

1

There are 1 best solutions below

1
On

You should be able to add it to metadata just fine. Just make sure you add an index on the metadata field (f.e. userid) that you want to query on:

db.colName.ensureIndex( { 'metadata.user_id' : 1 } );