pymongo - mongodb 的find()耗时太长,应该怎样优化?
世界只因有你
世界只因有你 2017-04-28 09:04:33
0
3
898

目的: 在超过10万条数据 随机 选取一条数据。
我的方法: data=db[item].find().skip(random_num).limit()
遇到问题: 耗费时间很长才能随机找到数据。根据profile测试,是因为find().怎么优化?

世界只因有你
世界只因有你

reply all(3)
仅有的幸福

It is recommended to do it according to the specific query conditions when randomly obtaining it. Do not skip directly.

某草草

Do you know mongo’s aggregation framework? Check it out, the key to high performance. As long as it is not cross-library or referenced, it can be used.

阿神

First create an index on the item, which can greatly improve the query speed. In addition, the random number conditions can be turned into specific query conditions (constructed with random numbers). In addition, the aggregation framework does not help with simple find queries like yours.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template