zoukankan      html  css  js  c++  java
  • pymongo的比较排序查询性能比较,sort参数和sort函数, find和find_one



    sort参数与sort函数

    官方文档中,find函数中的说明表明,在find中传参应该和cursor后面调用sort函数一样

    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. See sort() for details.


    查询条件和排序条件如下

    query = {
    # 'start': {'$lte': int_ip},
    'end': {'$gte': int_ip}
    }
    sort = [('end', 1)]

    sort作为入参查询方式
    cursor = db.aiwen.find(query, sort=sort, limit=1)

    sort函数调用方式
    db.aiwen.find(query).sort([('end', 1)]).limit(1)

    为了保证格式统一,将find_one替换成find函数
    sort参数方式调用 耗时  cost:1.97000002861
    sort函数方式调用 耗时  cost:1.97200012207

    但用Robomongo工具查询,发现时延很短
    image

    find_one函数

    cursor = db.aiwen.find_one(query, sort=sort)
    发现查询结果一下得到提升,与robomongo相当
    cost:0.00399994850159
    好记性不如烂笔头
  • 相关阅读:
    SSM简单实现文件上传和下载
    Web发送邮件
    scala写算法-快排
    scala写算法-从后缀表达式构造
    scalajs_初体验
    scala写算法-用小根堆解决topK
    scala-Future和Promise
    python基础之函数
    python基础知识(五)
    python基础知识(四)
  • 原文地址:https://www.cnblogs.com/inns/p/7246168.html
Copyright © 2011-2022 走看看