是否可以将数据从 MongoDB 迁移到 SQL-Server?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29986360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to migrate data from MongoDB to SQL-Server?
提问by Mian Asbat Ahmad
I searched around I found that there are ways to transfer/sync data from sql-server to mongodb. I also know that Mongodb contains collections instead of table and the data is stored differently. I want to know if it is possible to move data from mongodb to sql-server? If yes then what tools/topics should I look into.
我四处搜索,发现有多种方法可以将数据从 sql-server 传输/同步到 mongodb。我也知道 Mongodb 包含集合而不是表,并且数据的存储方式不同。我想知道是否可以将数据从 mongodb 移动到 sql-server?如果是,那么我应该研究哪些工具/主题。
回答by mucio
Of course it's possible, but you will need to find a way to force the flexibility of a document db like MongoDB into a RDBMS like SQL Server.
当然这是可能的,但是您需要找到一种方法来将像 MongoDB 这样的文档数据库的灵活性强加到像 SQL Server 这样的 RDBMS 中。
It means that you need to define how you want to handle missing fields (will it be a NULL in the db column? or a default value?) and other things that usually don't fit well in a relational database.
这意味着您需要定义您希望如何处理缺失的字段(它是 db 列中的 NULL 还是默认值?)以及其他通常不适合关系数据库的内容。
Said do, you can use an ETL tool able to connect to both databases, SSIS can be an example if you want to stay in the MicroSoft world (you can check this Importing MongoDB Data Using SSIS 2012to have an idea) or you can go for an open source tool like Talend Big Data Integrationwhich has a connector to MongoDB (and of course to SQL Server).
说做,您可以使用能够连接到两个数据库的 ETL 工具,如果您想留在 MicroSoft 世界中,SSIS 可以是一个示例(您可以查看使用 SSIS 2012 导入 MongoDB 数据以获得一个想法),或者您可以去对于像Talend Big Data Integration这样的开源工具,它有一个连接到 MongoDB(当然还有 SQL Server)的连接器。
回答by John A. De Goes
There is no way to directly move data from MongoDB to SQL Server. Because MongoDB data is non-relational, any such movement must involve defining a target relational data model in SQL Server, and then developing a transformation that can take the data in MongoDB and transform it into the target data model.
无法直接将数据从 MongoDB 移动到 SQL Server。由于 MongoDB 数据是非关系型数据,因此任何此类移动都必须涉及在 SQL Server 中定义目标关系数据模型,然后开发可以将 MongoDB 中的数据转换为目标数据模型的转换。
Most ETL tools such as Kettle or Talend can help you with this process, or if you're a glutton for punishment, you can just write gobs of code.
大多数 ETL 工具(例如 Kettle 或 Talend)可以帮助您完成此过程,或者如果您喜欢惩罚,则只需编写大量代码即可。
Keep in mind that if you need this transformation process to be online, or applied more than once, you may need to tweak it for any small changes in the structure or types of the data stored in MongoDB. As an example, if a developer adds a new field to a document inside a collection, your ETL process will need rethinking (possibly new data model, new transformation process, etc.).
请记住,如果您需要将此转换过程联机或多次应用,则可能需要针对 MongoDB 中存储的数据结构或类型的任何细微更改对其进行调整。例如,如果开发人员向集合内的文档添加新字段,您的 ETL 过程将需要重新思考(可能是新的数据模型、新的转换过程等)。
If you are not sold on SQL Server, I'd suggest you consider Postgres, because there is a widely-used open source tool called MoSQLthat has been developed expressly for the purpose of syncing a Postgres database with a MongoDB database. It's primarily used for reporting purposes (getting data out of MongoDB and into an RDBMS so one can layer analytical or reporting tools on top).
如果你不是在 SQL Server 上出售,我建议你考虑 Postgres,因为有一个广泛使用的开源工具叫做MoSQL,它是专门为同步 Postgres 数据库和 MongoDB 数据库而开发的。它主要用于报告目的(从 MongoDB 中获取数据并进入 RDBMS,以便可以在顶部分层分析或报告工具)。
MoSQL enjoys wide adoption and is well supported, and for badly tortured data, you always have the option of using the Postgres JSON data type, which is not supported by any analytics or reporting tools, but at least allows you to directly query the data in Postgres. Also, and now my own personal bias is showing through, Postgres is 100% open source, while SQL Server is 100% closed source. :-)
MoSQL 被广泛采用并且得到了很好的支持,对于严重扭曲的数据,您始终可以选择使用 Postgres JSON 数据类型,该数据类型不受任何分析或报告工具的支持,但至少允许您直接查询邮政。此外,现在我个人的偏见已经显现出来,Postgres 是 100% 开源,而 SQL Server 是 100% 闭源。:-)
Finally, if you are onlyextracting the data from MongoDB to make analytics or reporting easier, you should consider SlamData, an open source project I started last year that makes it possible to execute ANSI SQL on MongoDB, using 100% in-database execution (it's basically a SQL-to-MongoDB API compiler). Most people using the project seem to be using it for analytics or reporting use cases. The advantage is that it works with the data as it is, so you don't have to perform ETL, and of course it's always up to date because it runs directly on MongoDB. A disadvantage is that no one has yet built an ODBC / JDBC driver for it, so you can't directly connect BI tools to SlamData.
最后,如果您只是从 MongoDB 中提取数据以简化分析或报告,您应该考虑SlamData,这是我去年启动的一个开源项目,它可以使用 100% 数据库内执行在 MongoDB 上执行 ANSI SQL(它基本上是一个 SQL-to-MongoDB API 编译器)。大多数使用该项目的人似乎将其用于分析或报告用例。优点是它可以按原样处理数据,因此您不必执行 ETL,当然它始终是最新的,因为它直接在 MongoDB 上运行。一个缺点是目前还没有人为它构建一个 ODBC/JDBC 驱动程序,所以你不能直接将 BI 工具连接到 SlamData。
Good luck!
祝你好运!
回答by marijnz0r
There is a tool provided by MongoDB called mongoexportand it's capable of exporting csv files. These csv files can be easily imported into MySQL. Good luck!
MongoDB 提供了一个名为mongoexport的工具,它能够导出 csv 文件。这些 csv 文件可以轻松导入 MySQL。祝你好运!