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

mongoc_collection_find fails with top level $or, etc.

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      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'.
      

      Attachments

        Activity

          People

            jesse@mongodb.com A. Jesse Jiryu Davis
            matt.cotter Matt Cotter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: