mongodb query return command cursor .to iterate the cursor and get the data its very slow takes around 90 sec for 250 records .Can someone help
using pymongo 3.9.0
mongodb query return command cursor .to iterate the cursor and get the data its very slow takes around 90 sec for 250 records .Can someone help
using pymongo 3.9.0
Hi @Yogita_Pal,
First of all, welcome to the MongoDB Community.
Could you share your code?
All the best,
Rodrigo (a.k.a. Logwriter)
cursor= db.collection.aggregate(
[
{
'$addFields':
{
'yearSubstring': {'$substr': ["$__json.created_on", 0, 10]},
}
},
{
'$match': {
'$and': [{'yearSubstring': {'$gte': '12/01/2019'}}, {'yearSubstring': {'$lte': '12/02/2019'}}]
}
}
])
#query take around 4-5 seconds
while cursor and cursor.alive:
list_element= cursor.next()
items.append(list_element)
#but this while to read each cursor data take around 100 seconds
Just call list(cursor) to create a list of the results.
I had already done that before and tried again it also takes same takes same time .what is standard bench mark for reading 1000 records from mongodb server using pymongo 3.9 .
90 seconds for 250 records does not seem normal to me.
what is standard bench mark for reading 1000 records from mongodb server using pymongo 3.9
Assuming these are small documents (<1KB) they can all be returned in a single network roundtrip to the server and the total time should be roughly equal to the network latency.
Although in general the answer depends on a number of factors:
python3 -c 'import bson;print(bson.has_c())'
A final note, you can use cProfile to determine where the CPU time (not I/O time) is being spent:
python3 -m cProfile -s time myscript.py