Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-1522

Add mongoc_collection_find_with_opts



    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 1.5.0
    • 1.4.0
    • libmongoc
    • None
    • Fully Compatible


      New function takes options expressed as a free-form BSON document. Paves the way to a more flexible future API in which we can add support for arbitrary options without API expansions.

      mongoc_cursor_t *
      mongoc_collection_find_with_opts (mongoc_collection_t       *collection,
                                        const bson_t              *filter,
                                        const bson_t              *opts,
                                        const mongoc_read_prefs_t *read_prefs);

      The plan:

      1. mongoc_collection_find_with_opts translates to old-style _mongoc_cursor_new call with all the old parameters - done
      2. readConcern is prohibited - specs say drivers MAY allow it per-operation, we only allow it to be set on client, db, and collection, so let's not support it per-operation right now, and enforce that choice - done
      3. Test mongoc_collection_find_with_opts for the same scenarios as mongoc_collection_find - ensure it handles all the same server-specific cases (wire version, OP_QUERY vs "find" command, mongos vs mongod) - done
      4. Add "filter" and "opts" to mongoc_cursor_t struct. mongoc_collection_find_with_opts copies its "filter" and "opts" parameters to these fields of the mongoc_cursor_t - done
      5. When "filter" and "opts" are set, use them in the "find" command path instead of constructing from old fields in the mongoc_cursor_t - done
      6. When "filter" and "opts" are set, rewrite the OP_QUERY path to use them instead of the old fields (the work done for Step 1 is reusable here) - done
      7. Deal with maxAwaitTimeMS and test it with mongoc_collection_find_with_opts - done
      8. _mongoc_cursor_new drops its qflags, skip, limit, batch_size, fields, and read_concern parameters, gains an "opts" parameter. mongoc_collection_find_with_opts now calls it directly. mongoc_collection_find translates from its parameters to an "opts" document; e.g., batch_size=1 becomes {batchSize: 1}. Other _mongoc_cursor_new callers are also updated to create "opts" documents. - done
      9. Test that unrecognized opts fields are sent to server unmodified - done
      10. Delete old fields from mongoc_cursor_t struct: fields, write_concern, flags, skip, limit, batch_size, max_await_time_ms - done
      11. Update docs and NEWS - done
      12. Update signature for consistency with mongoc_collection_count_with_opts: (collection, filter, opts, read_prefs) - done
      13. Make the common strings like "awaitData" into macros - done
      14. Call _mongoc_cursor_new_with opts internally from mongoc_client_command, mongoc_client_find_databases, mongoc_collection_find, mongoc_cursor_new_from_command_reply, mongoc_database_find_collections - done
      15. Test _mongoc_n_return some more, it's been a bug factory in the past - done




            jesse@mongodb.com A. Jesse Jiryu Davis
            jesse@mongodb.com A. Jesse Jiryu Davis
            0 Vote for this issue
            5 Start watching this issue