[CXX-1722] How to set “contentType” field in GridFS? Created: 30/Jan/19  Updated: 27/Oct/23  Resolved: 01/Feb/19

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Betty Leung Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux OS (RHEL), mongocxx driver 3.4, and C++ 11.



 Description   

I'm writing a RESTful call to save JPEG files in my MongoDB instance. I would like to set the field contentType in the document when I upload to the fs.files collection. However I don't see a way to set that field even after checking the uploader and bucket classes.

How do I set the contentType field in the in a document in fs.files ?
 



 Comments   
Comment by Betty Leung [ 31/Jan/19 ]

Thank you for the info Kevin.

Comment by Kevin Albertson [ 31/Jan/19 ]

Hi betty.leung@interpreta.com,

The GridFS specification deprecated the contentType option with the rationale being:

Why is contentType deprecated?
Most fields in the files collection document are directly used by the driver, with the exception of: metadata, contentType and aliases. All information that is purely for use of the application should be embedded in the 'metadata' document. Users of GridFS who would like to store a contentType for use in their applications are encouraged to add a 'contentType' field to the ‘metadata’ document instead of using the deprecated top-level ‘contentType’ field.

The mongocxx::options::gridfs::upload options do not include the deprecated contentType, but do include the metadata option.

Best,
Kevin

Comment by Betty Leung [ 30/Jan/19 ]

This is the field I am trying to set:
https://docs.mongodb.com/v3.2/core/gridfs/#files.contentType

Generated at Wed Feb 07 22:03:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.