-
Type: Task
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: 3.5
-
Component/s: Performance, Query Operations
-
Environment:MongoDB Server: 3.2.11
OS: MacOS High Sierra and Oracle Linux 7
Python : 2.7
Pymongo cursor taking ~ 2 seconds, please suggest ways to optimize below query.
*Facts of query*
Records in MongoDB : 120,000
Indexed Key: emp_id
MongoDB Server: 3.2.11
PyMongo : 3.5
Python : 2.7
*Cursor*
To find a document from db, by using indexed field as filter and projecting only required fields, its consuming ~2 Seconds.
I am looking for ways to optimize this query so that it can be faster.
user_data = MongoldbAdaptor(**APP_CONFIG).db().collection_name.find_one( {"emp_id": 1234}, {'nameFirst': 1, 'nameLast': 1, 'emp_id': 1, } )
Elapsed Time: 1.829226017
_____________________________________________________________________________________
For Informational purpose, please refer same query using find()
def query_cursor(): cursor = MongoldbAdaptor(**APP_CONFIG).db().collection_name.find( {"emp_id": 1234}, {'nameFirst': 1, 'nameLast': 1, 'emp_id': 1, } ).limit(1) return cursor def get_user_data(): cursor = query_user_data() user_data = None for document in cursor: user_data = document return user_data print(get_user_data())
Elapsed Time for query_cursor: 0.00215888023376
Elapsed Time for get_user_data: 1.79128599167
- is duplicated by
-
PYTHON-1432 find_one() taking long time
- Closed
1.
|
find_one() taking long time | PYTHON-1432 | Closed | Unassigned |