简体   繁体   English

Java MongoDB Hadoop Connector是否有C#等效项?

[英]Is there a C# equivalent for the Java MongoDB Hadoop Connector?

I'm playing with Mobius (the C# language binding for Spark) and the C# Driver for MongoDB. 我正在玩Mobius (Spark的C#语言绑定)和MongoDB的C#驱动程序。 What I'm aiming to do is use MongoDB as the input/output for the Spark queries within my C# application. 我的目标是将MongoDB用作C#应用程序中Spark查询的输入/输出。 I know there's a Java MongoDB Hadoop Connector but I would like to continue using Mobius to write my Spark queries. 我知道有一个Java MongoDB Hadoop连接器,但我想继续使用Mobius编写我的Spark查询。

You could use MongoDB Spark Connector and DataFrame API in Mobius for querying MongoDB. 您可以在Mobius中使用MongoDB Spark Connector和DataFrame API来查询MongoDB。 The code to load data will look like 加载数据的代码如下所示

var mongoDbDataFrame = sqlContext.Read.Format("com.mongodb.spark.sql").Load()

Once the data is loaded, you could do Select(), Filter() operations on the DataFrame. 加载数据后,您可以在DataFrame上执行Select(),Filter()操作。 You could also register the DataFrame as TempTable for using SQL queries using the code template below 您还可以使用以下代码模板将DataFrame注册为TempTable以使用SQL查询

mongoDbDataFrame.RegisterTempTable("MongDbDataFrameTempTable")
sqlContext.Sql("SELECT <columns> FROM MongDbDataFrameTempTable WHERE <condition>")

Note that you need to include the connector and its dependencies in the classpath and "--jars" parameter could be used for that. 请注意,您需要在类路径中包括连接器及其依赖项,并且可以使用“ --jars”参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM