I have a JSON doc like the following:
x = {'ALPHA':{'A':{ 'T1':{ 'L':{'a':1,
'b':2,
'c':3,},
'S':{'a':1,
'b':2,
'c':3,}},
'T2':{'L':{'a':1,
'b':2,
'c':3,},
'S':{'a':1,
'b':2,
'c':3,}},
'T3':{'L':{'a':1,
'b':2,
'c':3,},
'S':{'a':1,
'b':2,
'c':3,}}
}
}
}
Where I can parse normally getting 'A', with a standard x['ALPHA']['A']. I thought the mongoDB equivalent would be mongo.find_one({'ALPHA':'A'}), but I am confused about this. Maybe I am creating the documents incorrectly?
Here is the case:
import pymongo
mong = pymongo.Connection()['ALPH']['AZ']
letter_dict = ('A','B','C','D')
for letter in letter_dict:
x = {'ALPHA':{letter :{ 'T1':{ 'L':{'a':1,
'b':2,
'c':3,},
'S':{'a':1,
'b':2,
'c':3,}},
'T2':{'L':{'a':1,
'b':2,
'c':3,},
'S':{'a':1,
'b':2,
'c':3,}},
'T3':{'L':{'a':1,
'b':2,
'c':3,},
'S':{'a':1,
'b':2,
'c':3,}}
}
}
}
mong.insert(x)
But when I try searching for 'A', It is either finding None, or returning a cursor, or an object id:
mong.find_one({'ALPHA':'A'})
>>>None
mong.find_one({},{'A':1})
>>>{u'_id': ObjectId('55f2eeb7c8b582120834de8f')}
Can someone give a hand?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire