I want to use the mongodb _id attribute to guarantee uniqueness in a name.
mongo_cursor_init( cursor, &conn, &database );
bson_iterator iterator[1];
bson_find( iterator, mongo_cursor_bson( cursor ), "name" );
const char *filename = bson_iterator_string( iterator );
bson_find( iterator, mongo_cursor_bson( cursor ), "_id" );
const char *mongoid = bson_iterator_string(iterator);
char name[255];
strcpy(name,filename);
strcat(name,".");
strcat(name,mongoid);
However, the variable mongoid does not get populated correctly (at all…). I’m not sure how to find the datatype of _id. Has anyone done this before? Thanks!
edit: i think the answer is in here, but not sure…
Hope this helps somebody…
Mongo _id to string:
string to Mongo _id: