[CXX-250] better api on GridFS and GridFile Created: 13/Jan/14  Updated: 21/Jun/23  Resolved: 07/Jan/15

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

Type: Improvement Priority: Major - P3
Reporter: Thomas Riccardi Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: cxxmove, legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

In SERVER-12315 I proposed an improvement of the remove api on GridFS.

In fact others key features are missing from the GridFS & GridFile classes.
The general idea is to be able to easily do CRUD operations:

  • Create: current storeFile() methods only allow to set fileName and contentType on the GridFile. According to GridFS Reference there are aliases and metadata too. Also, _fileName_should be optional, and it's not (we can set an empty filename with the buffer api, which is close to "optional", but not exactly the same; but we cannot even do that with tile file api).
  • Read: we need a full featured query api for "find": currently we have findFile() & list().
    • findFile() should be able to return a list of GridFiles. In fact it would be really useful to have a full-featured queyring api like db.collection.find(): query, skip, limit, sort; or maybe just accept a DBClientCursor to avoid duplicating the find() api.
    • list() is probably less useful if findFile() can return multiple GridFiles. If we keep it we could add a full-featured api like proposed findFile().
  • Update: GridFile is currently a read-only view of the db; we could add a method to update the fs.files fields (filename, contentType, aliases, metadata). I'm not sure about modifying the data itself. It would require more work anyway.
  • Delete: see SERVER-12315: we need a full featured query api for "remove", like the find api: query, skip, limit, sort; or maybe just accept a DBClientCursor.

A real use-case: multiple files with the same filename, I just want to get a GridFile of the last inserted file given a filename: I cannot use GridFS and GridFile to do that with the current API.



 Comments   
Comment by Adam Midvidy [ 07/Jan/15 ]

At this time we do not plan to make significant changes to the API of the legacy driver.

Comment by Thomas Riccardi [ 13/Jan/14 ]

We currently have no way to construct a GridFile from a cursor or a BSONObj, although it's what's done in private. It would thus be great to have a public or at least protected constructor for GridFile, instead of private.

Comment by Thomas Riccardi [ 13/Jan/14 ]

For the full api like find() there are also the read preferences, see this patch; which adds an optional readPrefMode paramater to many methods; and also optionally disables the ensureIndex (this performance patch is the only thing needed to dynamically create GridFS objects from parsing a URI for example).

Generated at Wed Feb 07 21:58:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.