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

mongoc_cursor_clone() ignores fields

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.1.0
    • Affects Version/s: 1.0.2
    • Component/s: None
    • Environment:
      Debian GNU Linux, 7.0, AMD 64Bit

      I have the following function:

      mongoc_cursor_t *
      get_cur(char *host, char *db, char *collection_name,
      mongoc_collection_t **collection_p,
      mongoc_client_t **client_p){
      mongoc_init();
      bson_t *query = NULL;
      bson_t *fields = NULL;
      query = bson_new ();
      fields = bson_new ();
      fields = BCON_NEW("_id", BCON_INT32 (0));

      mongoc_cursor_t *cursor;
      *client_p = mongoc_client_new("mongodb://localhost:27017/");
      *collection_p = mongoc_client_get_collection (*client_p, "test", "test");
      cursor = mongoc_collection_find(*collection_p, MONGOC_QUERY_NONE,
      0, 0, 0, query, fields, NULL);
      return cursor;

      I call this function with:

      cursor = get_cur(host, database, collection_name, &collection_p, &client_p);

      The first time I call curser next, it returns the fields without _id.
      I then clone with with:

      mongoc_cursor_t *cursor_copy;
      cursor_copy = mongoc_cursor_clone (cursor);

      And now when I do:

      while (mongoc_cursor_next (cursor_copy, &doc)) {
      jsstr = bson_as_json (doc, NULL);

      I see the filed `_id` returned.

      I expected the cursor to maintain the query and field properties, e.g.
      return documents without the field _id.

      Is this a bug or intended behaviour of mongoc_cursor_clone?
      If this is not a bug, how can I specify the fields, with out calling again my own function get_cur?

            Assignee:
            Unassigned Unassigned
            Reporter:
            oz123 Oz Tiram
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: