Performance Comparison of pymongo in comparative sorting query, sort parameter and sort function, find and find_one, pymongofind_one
Sort parameters and sort Functions
In the official documentation, the description in the find function indicates that the parameter in the find function should be the same as the sort function called after the cursor.
find
(
Filter = None,
Projection = None,
Skip = 0,
Limit = 0,
No_cursor_timeout = False,
Cursor_type = CursorType. NON_TAILABLE,
Sort = None,
Allow_partial_results = False,
Oplog_replay = False,
Modifiers = None,
Manipulate = True)
The query conditions and sorting conditions are as follows:
query = {
# 'start': {'$lte': int_ip},
'end': {'$gte': int_ip}
}
sort = [('end', 1)]
Sort as the input parameter query method
cursor = db.aiwen.find(query, sort=sort, limit=1)
Sort function call Method
db.aiwen.find(query).sort([('end', 1)]).limit(1)
To ensure unified format, replace find_one with the find function.
Cost: 1.97000002861
Cost: 1.97200012207
However, the Robomongo tool is used for query, and the latency is found to be very short.
Find_one Function
cursor = db.aiwen.find_one(query, sort=sort)
The query results are improved, which is equivalent to that of robomongo.
cost:0.00399994850159