pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <bdo id='M5win'></bdo><ul id='M5win'></ul>
<legend id='M5win'><style id='M5win'><dir id='M5win'><q id='M5win'></q></dir></style></legend>

      <small id='M5win'></small><noframes id='M5win'>

    1. <i id='M5win'><tr id='M5win'><dt id='M5win'><q id='M5win'><span id='M5win'><b id='M5win'><form id='M5win'><ins id='M5win'></ins><ul id='M5win'></ul><sub id='M5win'></sub></form><legend id='M5win'></legend><bdo id='M5win'><pre id='M5win'><center id='M5win'></center></pre></bdo></b><th id='M5win'></th></span></q></dt></tr></i><div class="mywc0y4" id='M5win'><tfoot id='M5win'></tfoot><dl id='M5win'><fieldset id='M5win'></fieldset></dl></div>

      <tfoot id='M5win'></tfoot>
    2. pymongo 中的快速或批量更新

      Fast or Bulk Upsert in pymongo(pymongo 中的快速或批量更新)

    3. <tfoot id='cCo4E'></tfoot>
    4. <small id='cCo4E'></small><noframes id='cCo4E'>

        • <bdo id='cCo4E'></bdo><ul id='cCo4E'></ul>

            <legend id='cCo4E'><style id='cCo4E'><dir id='cCo4E'><q id='cCo4E'></q></dir></style></legend>
                <tbody id='cCo4E'></tbody>

                <i id='cCo4E'><tr id='cCo4E'><dt id='cCo4E'><q id='cCo4E'><span id='cCo4E'><b id='cCo4E'><form id='cCo4E'><ins id='cCo4E'></ins><ul id='cCo4E'></ul><sub id='cCo4E'></sub></form><legend id='cCo4E'></legend><bdo id='cCo4E'><pre id='cCo4E'><center id='cCo4E'></center></pre></bdo></b><th id='cCo4E'></th></span></q></dt></tr></i><div class="mgqyme4" id='cCo4E'><tfoot id='cCo4E'></tfoot><dl id='cCo4E'><fieldset id='cCo4E'></fieldset></dl></div>
                本文介紹了pymongo 中的快速或批量更新的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                如何在 pymongo 中進行批量更新插入?我想更新一堆條目,一次做一個非常慢.

                How can I do a bulk upsert in pymongo? I want to Update a bunch of entries and doing them one at a time is very slow.

                幾乎相同問題的答案在這里:在 MongoDB 中批量更新/upsert?

                The answer to an almost identical question is here: Bulk update/upsert in MongoDB?

                接受的答案實際上并沒有回答問題.它只是提供了 mongo CLI 的鏈接以進行導入/導出.

                The accepted answer doesn't actually answer the question. It simply gives a link to the mongo CLI for doing import/exports.

                我也愿意解釋為什么做批量 upsert 是不可能的/不是最佳實踐,但請解釋解決此類問題的首選解決方案是什么.

                I would also be open to someone explaining why doing a bulk upsert is no possible / no a best practice, but please explain what the preferred solution to this sort of problem is.

                推薦答案

                現代版本的 pymongo(大于 3.x)將批量操作包裝在一致的接口中,該接口在服務器版本不支持批量操作的情況下降級.這在 MongoDB 官方支持的驅動程序中現在是一致的.

                Modern releases of pymongo ( greater than 3.x ) wrap bulk operations in a consistent interface that downgrades where the server release does not support bulk operations. This is now consistent in MongoDB officially supported drivers.

                所以編碼的首選方法是使用 bulk_write() 改為使用 UpdateOne 其他適當的操作動作代替.現在當然首選使用自然語言列表而不是特定的構建器

                So the preferred method for coding is to use bulk_write() instead, where you use an UpdateOne other other appropriate operation action instead. And now of course it is preferred to use the natural language lists rather than a specific builder

                舊文檔的直接翻譯:

                from pymongo import UpdateOne
                
                operations = [
                    UpdateOne({ "field1": 1},{ "$push": { "vals": 1 } },upsert=True),
                    UpdateOne({ "field1": 1},{ "$push": { "vals": 2 } },upsert=True),
                    UpdateOne({ "field1": 1},{ "$push": { "vals": 3 } },upsert=True)
                ]
                
                result = collection.bulk_write(operations)
                

                或者經典的文檔轉換循環:

                Or the classic document transformation loop:

                import random
                from pymongo import UpdateOne
                
                random.seed()
                
                operations = []
                
                for doc in collection.find():
                    # Set a random number on every document update
                    operations.append(
                        UpdateOne({ "_id": doc["_id"] },{ "$set": { "random": random.randint(0,10) } })
                    )
                
                    # Send once every 1000 in batch
                    if ( len(operations) == 1000 ):
                        collection.bulk_write(operations,ordered=False)
                        operations = []
                
                if ( len(operations) > 0 ):
                    collection.bulk_write(operations,ordered=False)
                

                返回的結果是BulkWriteResult 將包含匹配和更新文檔的計數器以及發生的任何更新插入"的返回 _id 值.

                對于批量操作數組的大小存在一些誤解.發送到服務器的實際請求不能超過 16MB BSON 限制,因為該限制也適用于發送到使用 BSON 格式的服務器的請求".

                There is a bit of a misconception about the size of the bulk operations array. The actual request as sent to the server cannot exceed the 16MB BSON limit since that limit also applies to the "request" sent to the server which is using BSON format as well.

                但是,這并不能控制您可以構建的請求數組的大小,因為實際操作無論如何只會以 1000 個批次發送和處理.唯一真正的限制是這 1000 條操作指令本身實際上并不會創建大于 16MB 的 BSON 文檔.這確實是一項艱巨的任務.

                However that does not govern the size of the request array that you can build, as the actual operations will only be sent and processed in batches of 1000 anyway. The only real restriction is that those 1000 operation instructions themselves do not actually create a BSON document greater than 16MB. Which is indeed a pretty tall order.

                批量方法的一般概念是減少流量",因為一次發送許多東西并且只處理一個服務器響應.減少附加到每個更新請求的開銷可以節省大量時間.

                The general concept of bulk methods is "less traffic", as a result of sending many things at once and only dealing with one server response. The reduction of that overhead attached to every single update request saves lots of time.

                這篇關于pymongo 中的快速或批量更新的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                How to refresh sys.path?(如何刷新 sys.path?)
                Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

              1. <tfoot id='AkH7O'></tfoot>

                <i id='AkH7O'><tr id='AkH7O'><dt id='AkH7O'><q id='AkH7O'><span id='AkH7O'><b id='AkH7O'><form id='AkH7O'><ins id='AkH7O'></ins><ul id='AkH7O'></ul><sub id='AkH7O'></sub></form><legend id='AkH7O'></legend><bdo id='AkH7O'><pre id='AkH7O'><center id='AkH7O'></center></pre></bdo></b><th id='AkH7O'></th></span></q></dt></tr></i><div class="yoi84eq" id='AkH7O'><tfoot id='AkH7O'></tfoot><dl id='AkH7O'><fieldset id='AkH7O'></fieldset></dl></div>

                <small id='AkH7O'></small><noframes id='AkH7O'>

                  • <legend id='AkH7O'><style id='AkH7O'><dir id='AkH7O'><q id='AkH7O'></q></dir></style></legend>
                    • <bdo id='AkH7O'></bdo><ul id='AkH7O'></ul>
                            <tbody id='AkH7O'></tbody>

                        1. 主站蜘蛛池模板: 丝印油墨_水性油墨_环保油墨油漆厂家_37国际化工 | 广州印刷厂_广州彩印厂-广州艺彩印务有限公司| 非标压力容器_碳钢储罐_不锈钢_搪玻璃反应釜厂家-山东首丰智能环保装备有限公司 | 工业插头-工业插头插座【厂家】-温州罗曼电气 | 南京展台搭建-南京展会设计-南京展览设计公司-南京展厅展示设计-南京汇雅展览工程有限公司 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 钢丝绳探伤仪-钢丝绳检测仪-钢丝绳探伤设备-洛阳泰斯特探伤技术有限公司 | 湖南成人高考报名-湖南成考网 | 大米加工设备|大米加工机械|碾米成套设备|大米加工成套设备-河南成立粮油机械有限公司 | 丝印油墨_水性油墨_环保油墨油漆厂家_37国际化工 | 净水器代理,净水器招商,净水器加盟-FineSky德国法兹全屋净水 | 识禅_对禅的了解,从这里开始 | 篷房[仓储-婚庆-展览-活动]生产厂家-江苏正德装配式帐篷有限公司 | 电磁铁_小型推拉电磁铁_电磁阀厂家-深圳市宗泰电机有限公司 | 特材真空腔体_哈氏合金/镍基合金/纯镍腔体-无锡国德机械制造有限公司 | 汽车润滑油厂家-机油/润滑油代理-高性能机油-领驰慧润滑科技(河北)有限公司 | 驾驶人在线_专业学车门户网站| 温湿度记录纸_圆盘_横河记录纸|霍尼韦尔记录仪-广州汤米斯机电设备有限公司 | 烟雾净化器-滤筒除尘器-防爆除尘器-除尘器厂家-东莞执信环保科技有限公司 | 硬齿面减速机[型号全],ZQ减速机-淄博久增机械| 板框压滤机-隔膜压滤机配件生产厂家-陕西华星佳洋装备制造有限公司 | 专业广州网站建设,微信小程序开发,一物一码和NFC应用开发、物联网、外贸商城、定制系统和APP开发【致茂网络】 | 在线钠离子分析仪-硅酸根离子浓度测定仪-油液水分测定仪价格-北京时代新维测控设备有限公司 | 石家庄装修设计_室内家装设计_别墅装饰装修公司-石家庄金舍装饰官网 | 磁力抛光机_磁力研磨机_磁力去毛刺机_精密五金零件抛光设备厂家-冠古科技 | 石油/泥浆/不锈钢防腐/砂泵/抽砂泵/砂砾泵/吸砂泵/压滤机泵 - 专业石油环保专用泵厂家 | 好笔杆子网 - 公文写作学习交流分享平台 | 【德信自动化】点胶机_全自动点胶机_自动点胶机厂家_塑料热压机_自动螺丝机-深圳市德信自动化设备有限公司 | 专注提供国外机电设备及配件-工业控制领域一站式服务商-深圳市华联欧国际贸易有限公司 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 万烁建筑设计院-建筑设计公司加盟,设计院加盟分公司,市政设计加盟 | 地磅-电子地磅维修-电子吊秤-汽车衡-无人值守系统-公路治超-鹰牌衡器 | 无锡门窗-系统门窗-阳光房-封阳台-断桥铝门窗厂[窗致美] | 中原网视台| 【铜排折弯机,钢丝折弯成型机,汽车发泡钢丝折弯机,线材折弯机厂家,线材成型机,铁线折弯机】贝朗折弯机厂家_东莞市贝朗自动化设备有限公司 | 钢丝绳探伤仪-钢丝绳检测仪-钢丝绳探伤设备-洛阳泰斯特探伤技术有限公司 | 美甲贴片-指甲贴片-穿戴美甲-假指甲厂家--薇丝黛拉 | 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 校车_校车价格_19座幼儿园校车_幼儿园校车_大鼻子校车 | 权威废金属|废塑料|废纸|废铜|废钢价格|再生资源回收行情报价中心-中废网 | 聚天冬氨酸,亚氨基二琥珀酸四钠,PASP,IDS - 远联化工 |