I am trying to retrieve an object out of my MongoDB instance. I am using the JsonCPP library.
Currently, what I am doing is:
system(("mongo --host " + host_name + " --port " + std::to_string(port) + " " + database_name + " --eval 'db." + collection_name + ".find({},{_id:0})' | tee -a return_from_db.json").c_str());
And parsing it later on using:
Json::Value json_object;
Json::Reader jsonreader.parse(ifstream_from_return_from_db_json, json_object, false);
As soon as I am not suppressing the _id field in my query, I'll get null values everywhere. The reason for this is as follows:
{
"_id": ObjectId("any_id")
}
- The object ID is not in double quotes.
Now my question: How can I extract the ID of a document using the jsoncpp library? Can I change something in the settings of my MongoDB instance to get syntactically correct id key-value mappings? I know, there is the MongoDB driver for CPP, but I cannot use it (for a couple of reasons...). Any help appreciated.