Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-59512

Introduce new find API to DBClientBase which uses IDL-generated FindCommandRequest



    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 5.2.0
    • None
    • None
    • Fully Compatible
    • QE 2021-11-01, QE 2021-11-15


      We will add new methods to DBClientBase called find() and findOne(). These perform the same role as the pre-existing DBClientBase::query() methods, but the caller specifies the find operation that they want to perform using the IDL-generated FindCommandRequest. This will make the internal client code easier to maintain, since whenever the find command IDL specification is modified, the client code will immediately benefit without any explicit changes necessary.

      Under the hood, the DBClientBase::find() methods will have slightly different logic for constructing the initial OP_MSG find request to send across the wire. In particular, DBClientBase::query() needs to upconvert the request as specified by the caller to a FindCommandRequest so that the find request can in turn be converted to an OP_MSG. This upconversion step is not necessary for the new find() API.

      This ticket will not complete the work to migrate all the callers off query() and onto find(). That will be achieved as followup work. Once that migration is complete, the query() API and its supporting code can be deleted. In particular the upconversion code mentioned above can be removed!

      Originally we had a slightly different plan in mind for achieving the same goal. The details of the old plan are outlined below for posterity.

      Original implementation plan

      Implement steps ##5-8, outlined in the description of SERVER-58670.

      5. Investigate and remove/replace the remaining four callers of fromBSONDeprecated():

      • (src/mongo/client/dbclient_rs.cpp) in DBClientReplicaSet::say under if (lastOp == dbQuery) check – is this code still reachable?
      • (src/mongo/client/dbclient_rs.cpp) in DBClientReplicaSet::call under if (toSend.operation() == dbQuery) check – is this code still reachable?
      • (src/mongo/db/repl/apply_ops.cpp) in _checkPrecondition – should/could preconditions use different format?
      • (src/mongo/scripting/mozjs/mongo.cpp) in MongoBase::Functions::find::call – should we still be supporting 'query/$query' here?

      6. When all Query construction from raw BSON is gone, the type will only handle a known fixed set of query properties, so it will become possible to replace the internal BSON field 'obj' with statically typed fields, and callers that inspect 'obj' will be able to switch to using specific statically typed accessors instead. There are currently 7 callers like this (search for getFullSettingsDeprecated()).
      7. Rename the Query type into QueryOptions (or FindOptions) and incorporate into it the other options that are currently passed to the query() APIs as separate arguments.
      8. Review and cleanup src/mongo/db/query/query_request_helper.cpp. There should be no vestiges of OP_QUERY left at this point.


        Issue Links



              david.storch@mongodb.com David Storch
              irina.yatsenko@mongodb.com Irina Yatsenko
              0 Vote for this issue
              3 Start watching this issue