我要把几个collection中的数据整合到一个collection中,来用一种更友好的数据结构,
用下面的python代码,db.index中有11W条数据,查出来组合再存入,估算了一下,在我的本子上完成要两个小时,各位大神,难道是我的方法不对?有办法优化吗
from pymongo import MongoClient
connection=MongoClient()
db=connection['wordnet']
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
if __name__ == '__main__':
domerge()
用下面的python代码,db.index中有11W条数据,查出来组合再存入,估算了一下,在我的本子上完成要两个小时,各位大神,难道是我的方法不对?有办法优化吗
from pymongo import MongoClient
connection=MongoClient()
db=connection['wordnet']
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
if __name__ == '__main__':
domerge()
