Azure DocumentDB与MongoDB协议Spark集成

时间:2017-04-24 15:23:10

标签: mongodb pyspark azure-cosmosdb

我想使用DocumentDB,但PySpark没有连接器。看起来DocumentDB也支持MongoDB Protocol as mentioned here,这意味着所有现有的MongoDB驱动程序都应该可以工作。由于有PySpark connector for MongoDB,我想尝试一下。

df = spark.read.format("com.mongodb.spark.sql.DefaultSource").load()

这会引发错误。

com.mongodb.MongoCommandException: Command failed with error 115: ''$sample' is not supported' on server example.documents.azure.com:10250. The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 115, "errmsg" : "'$sample' is not supported", "$err" : "'$sample' is not supported" }

看起来DocumentDB MongoDB API并不支持所有MongoDB功能,但我找不到任何文档。或者我错过了其他什么?

1 个答案:

答案 0 :(得分:3)

  

我想使用DocumentDB,但PySpark没有连接器。

2017年4月初可以预览Spark to DocumentDB connector(包括pyDocumentDB package)。

  

看起来DocumentDB也支持MongoDB Protocol as mentioned here,这意味着所有现有的MongoDB驱动程序都可以运行

DocumentDB支持用于通信的MongoDB有线协议,并将其版本报告为MongoDB 3.2.0,但这并不意味着它是完全支持所有MongoDB功能的直接替换(或者DocumentDB实现具有相同行为的功能)和限制)。目前值得注意的是对MongoDB聚合管道的任何支持,其中包括PySpark连接器期望在声称为MongoDB 3.2的服务器连接时可用的$sample运算符。

您可以在问题中引用的DocumentDB API for MongoDB文档的评论中找到更多潜在兼容性问题的示例。