【问题标题】:Update column values while processing the mysqldb with mongify在使用 mongify 处理 mysqldb 时更新列值
【发布时间】:2015-10-25 07:09:23
【问题描述】:

我正在使用 mongify 将我的 mysqldb 迁移到 mongodb。我面临的问题是如何修改 before_save 块中特定列的值?

考虑以下示例:- 我在一个字符串格式的表中有以下列:

"assets" : "{\"original\": [], \"thumbnail\": [], \"type\": []}"

现在我需要将其转换为 json 对象,然后再将其写入 Mongify 的 before_save 块中的 mongo。有什么帮助吗?

【问题讨论】:

    标签: javascript json node.js mongodb mongify


    【解决方案1】:

    您可以执行以下操作:

    before_save do |row|
      values = eval(row.assets) # this would give you a ruby object
      row.merge(values)         # this would combine the hashes together
    end
    

    祝你好运!

    【讨论】:

    • 小心使用 eval(),根据 row.assets 字段中的数据,这可能会对您的系统造成不良影响。
    猜你喜欢
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    相关资源
    最近更新 更多