Performance Comparison of pymongo in comparative sorting query, sort parameter and sort function, find and find_one, pymongofind_one

Source: Internet
Author: User
Tags robomongo

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)


  • Sort(Optional): a list of (key, direction) pairs specifying the sort order for this query. Seesort()For details.


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.