mongodb3的几个小坑

Posted sinpinle的咖啡馆

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mongodb3的几个小坑相关的知识,希望对你有一定的参考价值。


1.关于账号密码

如果账号密码中含有特殊符号,例如@&:等等

需要使用urllib.parser

import urllib.parser

USERNAME = urllib.parse.quote_plus(MONGODB_USER)
PASSWORD = urllib.parse.quote_plus(MONGODB_PWD)
MONGODB_DEFAULT_URL = 'mongodb://%s:%s@ip:port/db'\
                     
% (USERNAME, PASSWORD)

2.出现如下异常

pymongo.errors.ServerSelectionTimeoutError: No servers found yet

client = MongoClient(MONGODB_URL, connect=False)

加上connect=False


We're investigating this problem, tracked in PYTHON-961. You may be able to work around the issue by passing connect=False when creating instances of MongoClient. That defers background connection until the first database operation is attempted, avoiding what I suspect is a race condition between spin up of MongoClient's monitor thread and multiprocess forking.


参考:

https://stackoverflow.com/questions/31030307/why-is-pymongo-3-giving-serverselectiontimeouterror


以上是关于mongodb3的几个小坑的主要内容,如果未能解决你的问题,请参考以下文章