C# GridFS, custom index on metadata

219 views
Skip to first unread message

Jens Christiansen

unread,
Jun 17, 2018, 6:47:37 PM6/17/18
to mongodb-user
Hi

How do I in C# create an index on custom field in the metadata of GridFS?

I'm currently adding a custom object as metadata and I really like to add an index to one of the attributes in the object.

Regards,
Jens Christiansen

Wan Bachtiar

unread,
Jun 21, 2018, 2:35:44 AM6/21/18
to mongodb-user

How do I in C# create an index on custom field in the metadata of GridFS?

Hi Jens,

I’m assuming you’re referring to the files.metadata.
GridFS stores files in two collections, chunks and files.
For the metadata fields in the files, you can just create an index as any other index.

For example, to add an index on a files metadata field called foo:

var collection = database.GetCollection<BsonDocument>("fs.files");
var keys = Builders<BsonDocument>.IndexKeys.Ascending("metadata.foo");

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages