Say, I inserted the following document using the mongo command line or shell:
db.Users.insert(
{
"user info":{
"user name" : "Joe",
"password" : "!@#%$%" ,
"Facebook" : "aaa",
"Google" : "joe z"
}
}
)
Then this entry is logged into the database with a system created ID.
If I want to achieve the following command line which only returns the value of a specific filed (_id in this case), using the cxx driver how should I do it?
Here is the command line:
db.Users.find({"user info.user name": "Joe"}, {"_id":1})
I tried the following C++ code
bsoncxx::builder::stream::document document{} ;
document<<"user info.user name"<<"Joe"<<"_id"<<1;
auto cursor = myCollection.find(document.view());
for (auto && doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
It simply give me nothing.
If I set
document<<"user info.user name"<<"Joe"
Then it returns the entire JSON message for me.
Please let me know if you have any better ideas.