gpt4 book ai didi

mongodb - 为什么PyMongo会提供不支持的投影选项: $substr when listing collections?

转载 作者:行者123 更新时间:2023-12-03 16:27:49 25 4
gpt4 key购买 nike

我有以下代码:

client = MongoClient(uri)
db = client['my_db']
print(db.collection_names())
#print(db.list_collection_names())

我得到了错误

File "C:\Users\gwerner004\eclipse-workspace\MongoTestRasa\FirstTest.py", line 17, in connect print(db.collection_names()) File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\pymongo\database.py", line 715, in collection_names nameOnly=True, **kws)] File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\pymongo\database.py", line 677, in list_collections **kwargs) File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\pymongo\database.py", line 651, in _list_collections cursor = self._command(sock_info, cmd, slave_okay)["cursor"] File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\pymongo\database.py", line 514, in _command client=self.__client) File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\pymongo\pool.py", line 579, in command unacknowledged=unacknowledged) File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\pymongo\network.py", line 150, in command parse_write_concern_error=parse_write_concern_error) File "C:\Users\gwerner004\AppData\Local\Programs\Python\Python36\lib\site-packages\pymongo\helpers.py", line 155, in _check_command_response raise OperationFailure(msg % errmsg, code, response) pymongo.errors.OperationFailure: Unsupported projection option: $substr



为什么这样的基本操作会失败?我在Windows 10上运行并使用Python 3.6.7。我的PyMongo是3.7.2

最佳答案

$ substr运算符可用于当前所有受支持的MongoDB版本(2.6-4.4):

> db.foo.aggregate([{$project:{"name": {"$substr": ["$name", 2, -1]}}}])
{ "_id" : ObjectId("5fc032e56bc5b2e2216cdd08"), "name" : "llo" }
很可能您使用的是古老的MongoDB安装,或者使用其中的一条注释,模仿了像CosmosDB这样的模仿数据库,其行为不像MongoDB本身那样(官方MongoDB驱动程序也不支持)。

关于mongodb - 为什么PyMongo会提供不支持的投影选项: $substr when listing collections?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55497663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com