[CDRIVER-482] mongoc_cursor_clone() ignores fields Created: 10/Dec/14  Updated: 19/Oct/16  Resolved: 27/Jan/15

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.0.2
Fix Version/s: 1.1.0

Type: Bug Priority: Minor - P4
Reporter: Oz Tiram Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver, query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Debian GNU Linux, 7.0, AMD 64Bit



 Description   

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?



 Comments   
Comment by Githook User [ 27/Jan/15 ]

Author:

{u'username': u'hanumantmk', u'name': u'Jason Carey (hanumantmk)', u'email': u'jcarey@argv.me'}

Message: CDRIVER-482 mongoc_cursor_clone() ignores fields

Correctly propogate the fields parameter in copied cursors. We copied
the bson, but not the flag that indicated that we'd actually set
something.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/030eee408235a8ad8d62c654b7086a0d47c789fb

Generated at Wed Feb 07 21:09:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.