def domerge(): allindex=db.index.find({}) i=0 for indexitem in allindex: word={} word['word']=indexitem['word'] word['concept']=[] for conceptitem in indexitem['concepts']: concept={} concept['num']=conceptitem concept['synonyms']=db.synonyms.find_one({"concept":conceptitem})['synonymses'] concept['gloss']=db.gloss.find_one({"concept":conceptitem})['gloss_en'] word['concept'].append(concept) db.mergedata.insert(word) i=i+1 print i