久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <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="qwawimqqmiuu" 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="qwawimqqmiuu" id='cCo4E'><tfoot id='cCo4E'></tfoot><dl id='cCo4E'><fieldset id='cCo4E'></fieldset></dl></div>
                本文介紹了pymongo 中的快速或批量更新的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

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

                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.

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

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

                接受的答案實(shí)際上并沒(méi)有回答問(wèn)題.它只是提供了 mongo CLI 的鏈接以進(jìn)行導(dǎo)入/導(dǎo)出.

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

                我也愿意解釋為什么做批量 upsert 是不可能的/不是最佳實(shí)踐,但請(qǐng)解釋解決此類問(wèn)題的首選解決方案是什么.

                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.

                推薦答案

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

                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 其他適當(dāng)?shù)牟僮鲃?dòng)作代替.現(xiàn)在當(dāng)然首選使用自然語(yǔ)言列表而不是特定的構(gòu)建器

                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)
                

                或者經(jīng)典的文檔轉(zhuǎn)換循環(huán):

                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)
                

                返回的結(jié)果是BulkWriteResult 將包含匹配和更新文檔的計(jì)數(shù)器以及發(fā)生的任何更新插入"的返回 _id 值.

                對(duì)于批量操作數(shù)組的大小存在一些誤解.發(fā)送到服務(wù)器的實(shí)際請(qǐng)求不能超過(guò) 16MB BSON 限制,因?yàn)樵撓拗埔策m用于發(fā)送到使用 BSON 格式的服務(wù)器的請(qǐng)求".

                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.

                但是,這并不能控制您可以構(gòu)建的請(qǐng)求數(shù)組的大小,因?yàn)閷?shí)際操作無(wú)論如何只會(huì)以 1000 個(gè)批次發(fā)送和處理.唯一真正的限制是這 1000 條操作指令本身實(shí)際上并不會(huì)創(chuàng)建大于 16MB 的 BSON 文檔.這確實(shí)是一項(xiàng)艱巨的任務(wù).

                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.

                批量方法的一般概念是減少流量",因?yàn)橐淮伟l(fā)送許多東西并且只處理一個(gè)服務(wù)器響應(yīng).減少附加到每個(gè)更新請(qǐng)求的開(kāi)銷(xiāo)可以節(jié)省大量時(shí)間.

                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.

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

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

                相關(guān)文檔推薦

                python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個(gè)模塊和類)
                Configuring Python to use additional locations for site-packages(配置 Python 以使用站點(diǎn)包的其他位置)
                How to structure python packages without repeating top level name for import(如何在不重復(fù)導(dǎo)入頂級(jí)名稱的情況下構(gòu)造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(分發(fā)帶有已編譯動(dòng)態(tài)共享庫(kù)的 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="qwawimqqmiuu" 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. 主站蜘蛛池模板: 成人国产午夜在线观看 | 欧美日产国产成人免费图片 | 久久久免费电影 | 国产三区精品 | 九九免费在线视频 | 国产日韩欧美一区二区 | 在线播放国产一区二区三区 | 五月天激情电影 | 国产一区二区三区四区五区加勒比 | 日本精品裸体写真集在线观看 | 欧美日韩一区二区在线观看 | 亚洲一区二区在线 | 一区二区三区视频在线 | www天天操| 日本欧美视频 | 日韩视频91 | 黄色免费av| 日韩在线日韩 | 久久tv在线观看 | 国产成人精品久久二区二区91 | 欧美一级艳情片免费观看 | 综合欧美亚洲 | 黄色视频a级毛片 | 亚洲欧美中文日韩在线v日本 | 97精品久久 | 久久精品色欧美aⅴ一区二区 | 日韩高清在线 | 亚洲高清成人在线 | 亚洲一区二区精品视频 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 中文字幕日韩一区 | 亚州成人 | 国产精品国产三级国产aⅴ中文 | 精品久久久久久亚洲综合网站 | 成人免费在线播放 | 国产伦精品一区二区 | 午夜精品91 | 欧美性网 | 男女羞羞视频在线观看 | 国产成人精品一区二区在线 | 欧美日韩精品在线一区 |