【问题标题】:Remove a child object in Fauna DB删除 Fauna DB 中的子对象
【发布时间】:2021-12-09 10:59:05
【问题描述】:

我需要在 FQL 中删除一个子对象。让我用下面的例子来演示:

{
    "1": {
        "name": "test"
    },
    "2": {
        "name": "test2"
    }
}

我希望这个 JSON 看起来像这样:

{
    "1": {
        "name": "test"
    }
}

是否有可以帮助我的 FQL 函数?

【问题讨论】:

标签: javascript facebook-fql document-database faunadb jamstack


【解决方案1】:

当您在 Fauna 中将键的值设置为 null 时,它会从对象中删除。在您的示例中,假设 ref 是有效的 Reference

Update(ref, { "2": null })

将从对象中删除键 "2" 及其关联值,留下:

{ "1": { "name": "test" } }

【讨论】:

    【解决方案2】:

    对于裸对象,您可以使用Merge 函数通过将对象键的值设置为null 来移除对象键:

    > Merge({"1": { "name": "test" }, "2": { "name": "test2" }}, { "2": null })
    { '1': { name: 'test' } }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-05
      • 2021-11-11
      • 1970-01-01
      • 2018-07-30
      • 2019-05-12
      • 2018-12-27
      • 2012-12-09
      • 1970-01-01
      相关资源
      最近更新 更多