Python 无效的管道选项

Python 无效的管道选项,python,mongodb,apache-spark,pyspark,Python,Mongodb,Apache Spark,Pyspark,尝试在使用pyspark之前设置并定义管道 filter_users="[{'$and': [{'user': {'$in': ['player','npc']}}]}]" spark.read.format("com.mongodb.spark.sql.DefaultSource"). \ option("spark.mongodb.input.uri", 'data_users'). \ option

尝试在使用pyspark之前设置并定义管道

filter_users="[{'$and': [{'user': {'$in': ['player','npc']}}]}]"
spark.read.format("com.mongodb.spark.sql.DefaultSource"). \
        option("spark.mongodb.input.uri", 'data_users'). \
        option('pipeline',filter_users).load()
返回错误:

pyspark.sql.utils.IllegalArgumentException:requirement failed: Invalid Aggregation map Map(uri -> mongodb://localhost:27017/local.pii_val?readPreference=primaryPreferred, pipeline -> ["[{$and: [{\'user\': {\'$in\': [\'player\',\'npc\']}}]}]"]):
还尝试删除中运算符和或之间的then“”


谢谢。

您的查询不是聚合管道。见医生

您必须将查询放入
$match
对象中

filter_users="[{'$match: {'$and': [{'user': {'$in': ['player','npc']}}]}}]"

非常感谢您的回答@AlexisG