2024-09-27 17:39:19 发布
网友
我需要删除基于字段“X”的唯一值的重复条目。它在mongodb shell中运行良好:
db.collection.ensureIndex({x' : 1},{unique: true, dropDups: true})
我想用pymongo运行它,我使用的代码如下:
此代码引发:
TypeError: if no direction is specified, key_or_list must be an instance of list
我哪里出错了?在
在几个方面,pymongo调用的语法错误。假设“collection”是集合的名称,这应该可以工作。在
db.collection.ensure_index([("x" , pymongo.ASCENDING), ("unique" , True), ("dropDups" , True)])
Pymongo(和Python)需要一个键方向对列表,而不是Dict,因为Dict是无序的。升序索引的语法也是pymongo.升序. 最后,unique和dropDups不需要“$”。在
在几个方面,pymongo调用的语法错误。假设“collection”是集合的名称,这应该可以工作。在
Pymongo(和Python)需要一个键方向对列表,而不是Dict,因为Dict是无序的。升序索引的语法也是pymongo.升序. 最后,unique和dropDups不需要“$”。在
相关问题 更多 >
编程相关推荐