mongo常見錯誤


  1. BulkWriteError: batch op errors occurred
    原因:一般90%以上都是id重復了
    解決方式: 字符串拼接的id要格外注意,尤其 ip,port拼接

  2. mongo AutoReconnect: 127.0.0.1:19868: [Errno 24] Too many open files
    原因:多線程操作mongo,linux文件默認打開數較小
    解決方式:
    1)修改當前交互終端的limit值
    查詢當前終端的文件句柄數: ulimit -n 回車,一般的系統默認的1024.
    修改文件句柄數為65535,ulimit -n 65535.此時系統的文件句柄數為65535.

    2)將ulimit 值添加到/etc/profile文件中(適用於有root權限登錄的系統)
    為了每次系統重新啟動時,都可以獲取更大的ulimit值,將ulimit 加入到/etc/profile 文件底部。
    echo ulimit -n 65535 >>/etc/profile
    source /etc/profile #加載修改后的profile
    ulimit -n #顯示65535,修改完畢!

    3)都以為大功告成了,可以突然發現自己再次登錄進來的時候,ulimit的值還是1024,這是為什么呢?
    關鍵的原因是你登錄的用戶是什么身份,是不是root用戶,由於服務器的root用戶權限很大,一般是不能用來登錄的,都是通過自己本人的登錄權限進行登錄,並通過sudo方式切換到root用戶下進行工作。 用戶登錄的時候執行sh腳本的順序:
    /etc/profile.d/file
    /etc/profile
    /etc/bashrc
    /mingjie/.bashrc
    /mingjie/.bash_profile
    感謝 weixin_33755847 的分享。 https://blog.csdn.net/weixin_33755847/article/details/92928384
    3.mongo插入單條數據報錯如下:
    2020-07-13T20:11:16.274+0800 E QUERY [thread1] SyntaxError: missing } after property list @(shell):1:35
    原因:在mongo中存儲時,列表類型的數據要轉換為字符串

  3. 插入數據報錯:
    E11000 duplicate key error collection: measurescan.measure_all index: id d
    解決方式:刪除索引,指定唯一索引,或者不指定索引,自己生成id
    db.users.getIndexes() 輸出結果是包含多個對象的數組
    db.users.dropIndex({"username":1})
    db.users.dropIndex({你項目的key:value}) 只保留一個 _id作為主鍵
    db.users.getIndexes() 查看是否只有一個_id

  4. 數據已插入,且能查到,但是報 batch op errors occurred 錯誤
    原因:

  5. document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
    原因:傳遞給insertMany或者insertOne的參數不是一個真正的json結構,一般如果使用bulk_write,則需要轉換為 from pymongo import InsertOne 類型,但insertMany或者insertOne不需要
    可在插入前進行json.dumps和json.loads操作


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM