mysql – 如何使用mongify将两个表合并为一个表

我打算使用低架构更改将我的应用程序数据库从Mysql迁移到Mongo.在我的新模式中,我将两个Mysql表合并为一个Mongo集合.我想使用mongify(https://github.com/anlek/mongify)gem将我现有的Mysql数据填充到Mongo中,使用更新的模式.

这该怎么做?有没有办法在mongify中将两个Mysql表合并为一个?

Mysql表

user
    id
    name
    nickname
    type

user_role
    id
    role
    alias
    user_id

我将以上两个表合并为Mongo中的单个集合

user
    id
    name
    type
    role
    alias

最佳答案
尝试左连接:(表将合并)

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;

将该数据导出为sql格式并将其上传到mongodb

SELECT country INTO customerCountry
 FROM customers
 WHERE customerNumber = p_customerNumber;

    CASE customerCountry -- Here you have to see if that alias data is set
 WHEN  'USA' THEN
    SET p_shiping = '2-day Shipping'; -- here you have to write Update Query
 ELSE
    SET p_shiping = '5-day Shipping';
 END CASE;

我想这可能会对你有所帮助

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。