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

mongoc_collection_find_with_opts() does not work with multiple filters

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.5.0, 1.6.0, 1.7.0
    • Component/s: None
    • Environment:
      MongoDB 2.6 / MongoDB 3.4

      As soon as I moved to 1.7.0 and rewrote the code to use `mongoc_collection_find_with_opts()`, my filtering tests are starting to fail. Assuming we're working with this collection:

      {_id: ..., "foo": "A"}
      {_id: ..., "foo": "B"}
      {_id: ..., "foo": "C"}
      {_id: ..., "foo": "D"}
      

      My pre-libmongoc-1.7.0 testing code used to construct the following filters (printed with `bson_as_json()` here) then pass them to `mongoc_collection_find()`:

      `{ "$query" : { "opensips" : { "$lt" : "D" } } }`, gives 3 results. Correct.
      `{ "$query" : { "$and" : [ { "foo" : { "$lt" : "D" } }, { "foo" : { "$gte" : "A" } } ] } }`, gives 3 results. Correct.
      

      Now, I have updated the code to match the 1.7.0 API. Thanks to the new function, we can simplify the filters – here are the JSON views of the new filters, along with their results after passing them to the new `mongoc_collection_find_with_opts()`:

      `{ "foo" : { "$lt" : "D" } }`, gives 3 results. Correct.
      `{ "$and" : [ { "foo" : { "$lt" : "D" } }, { "foo" : { "$gte" : "A" } } ] }`, gives 0 results. Wrong!
      

      Moreover, the 2nd query literally works if I hit it in the console, so either I'm doing something terribly wrong (forgetting some flag / API call / shouldn't be doing string comparisons anymore, etc.), or there is a good chance there is a bug in the 1.7.0 driver.

      Any advice would be appreciated! Thanks!

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            liviuc Liviu Chircu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: