使用Djongo的Django中的Mongodb错误:pymongo.errors.OperationFailure:过滤器中不受支持的类型

时间:2019-06-09 23:56:43

标签: django python-3.x pymongo-3.x djongo

我试图在运行时将Django项目连接到MongoDB集群:

py manage.py runserver

py manange.py migrate

它一直显示相同的错误:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
    self.check_migrations()
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 453, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
    self.build_graph()
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\recorder.py", line 73, in applied_migrations
    if self.has_table():
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\introspection.py", line 48, in table_names
    return get_names(cursor)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\introspection.py", line 43, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\djongo\introspection.py", line 46, in get_table_list
    for c in cursor.db_conn.collection_names(False)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\database.py", line 715, in collection_names
    nameOnly=True, **kws)]
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\database.py", line 677, in list_collections
    **kwargs)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\database.py", line 631, in _list_collections
    session=tmp_session)["cursor"]
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\database.py", line 514, in _command
    client=self.__client)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\pool.py", line 579, in command
    unacknowledged=unacknowledged)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\network.py", line 150, in command
    parse_write_concern_error=parse_write_concern_error)
  File "C:\Users\marlo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\helpers.py", line 155, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: unsupported type in filter

我的setting.py配置为:

DATABASES = {
'default': {
    'ENGINE': 'djongo',
    'NAME': 'database_django',
    'HOST': 'mongodb+srv://xxxxxx:aaaaaa@isssgeneral-sfm0v.mongodb.net/test?retryWrites=true&w=majority',
    'PORT': 27017,
    'USERNAME': 'xxxxxx',
    'PASSWORD': 'aaaaaa' 
}
}

我的python环境如下:

pymongo            3.7.0
Django             2.2.2 
djongo             1.2.32
sqlparse           0.2.4
dnspython          1.16.0

我已经尝试过使用this post解决方案,该解决方案建议将pymongo降级到3.5.1版本,该版本已经尝试过但没有用。实际上,该项目以前在pymongo == 3.7版本中工作(我目前在环境中拥有该版本)。

我已经将此Django项目配置为连接到本地服务器,并且可以正常工作,显然主机名有些不适合。集群配置没有问题(我认为),因为我有一个直接连接到同一集群的Jupyter Notebook。

真的不知道我的项目发生了什么,突然停止了与我的Mongodb集群的连接。谁能帮助我找到解决该问题的方法?

谢谢社区。

0 个答案:

没有答案