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?