Mongoc and passing through mongo shell commands


I have very specific issue. I must work through a C program to access a mongo database.

If i connect to a mongo database with a simple C program like this :

mongoc_init ();
client = mongoc_client_new ("mongodb://user:pass@localhost:27017/?authSource=admin");
collection = mongoc_client_get_collection (client, "DB", "Collection");

I would now like to simply pass to this connection a shell script like this:
str = ‘db.DB.Collection.insert(name:“bob”)’

My_Mongo_Command(client, collection, str);

and have it return any output from the command as it would on the mongo command line.
I have not been able to find anything like this in the documentation but maybe i am blind. :slight_smile:


It’s the same for me. If you get a solution, please contact me.

Discover the problem is “mongoc_init();”, so decided to tested in simple C program, when commented de “mongo_init();” line, the program go perfect.

My setup is QT Creator (QT 5.13)