Consider this mongodb document:
{
"_id:"0,
"firstname":"Tom",
"profiles" : [
{
"profile_name": "tom",
"reward_programs:[
{
'program_name':'American',
'username':'tomdoe',
},
{
'program_name':'Delta',
'username':'tomdoe',
}
]
"settings": {
'auto_update': "False"
}
},
{
"profile_name": "harry",
"reward_programs:[
{
'program_name':'American',
'username':'car',
'account':'train',
},
{
'program_name':'Delta',
'username':'harrydoe',
}
]
"settings": {
'auto_update': "False"
}
}
]
}
How would I retrieve just the 'settings' dictionary for a particular profile name? Let's use 'harry' in the example. I have tried:
result = users.find_one({'_id': request._id, 'profiles.profile_name': 'harry'}, {'_id': 0, 'profiles.$.settings': 1})
But this retrieves the entire dictionary of profile_name:'harry'
{
'profiles':
{
"profile_name": "harry",
"reward_programs:[
{
'program_name':'American',
'username':'car',
'account':'train',
},
{
'program_name':'Delta',
'username':'harrydoe',
}
]
"settings": {
'auto_update': "False"
}
}
}
I would prefer getting the result as
{
"profiles" : [
{
"settings": {
'auto_update': "False"
}
}
]
}
And if simple enough I would even prefer:
{
"settings": {
'auto_update': "False"
}
}
I obviously have my projection messed up but I don't know how to fix it. Suggestions?