mongoc_collection_find fails with top level $or, etc.

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      When trying to do

      #include <mongoc.h>
      #include <stdio.h>
      #include <stdlib.h>
      
      int
      main (int   argc,
            char *argv[])
      {
         bson_error_t error;
         const bson_t *out;
         bson_t *query;
         mongoc_client_t *client;
         mongoc_collection_t *collection;
         mongoc_cursor_t *cursor;
      
         mongoc_init ();
      
         client = mongoc_client_new ("mongodb://127.0.0.1:27017/");
         collection = mongoc_client_get_collection (client, "test", "restaurants");
         query = BCON_NEW("$or", "[", "{", "cuisine", "Italian", "}",
                                      "{", "address.zipcode", "10036", "}", "]");
         cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 1, 0, query, NULL, NULL);
      
         if (mongoc_cursor_next(cursor, &out)) {
            printf("document found\n");
         } else if (mongoc_cursor_error(cursor, &error)) {
            printf ("error: %s\n", error.message);
         } else {
            printf("no documents found\n");
         }
      
         bson_destroy (query);
         mongoc_cursor_destroy (cursor);
         mongoc_collection_destroy (collection);
         mongoc_client_destroy (client);
      
         mongoc_cleanup ();
      
         return EXIT_SUCCESS;
      }
      

      the new mongoc_collection_find sends the command

      { find: "restaurants", or: [ { cuisine: "Italian" }, { address.zipcode: "10036" } ] }
      

      which can’t be parsed by the server and results in an error.

      error: Failed to parse: { find: "restaurants", or: [ { cuisine: "Italian" }, { address.zipcode: "10036" } ], limit: 1 }. Unrecognized field 'or'.
      

              Assignee:
              A. Jesse Jiryu Davis
              Reporter:
              Matt Cotter (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: