如何从 faunadb 的文档中删除特定元素?

How can I delete a specific element from a document in faunadb?

例如:

我该如何改变这个 -

{
"Name": "UserName",
"Ref": [
  {"id1": "ajbdkfb323"},
  {"id2": "fguqge7681"},
  {"id3": "chv76aavbb"}
  ],
"day": "Wednesday"
}

到这个-

{
"Name": "UserName",
"Ref": [
  {"id1": "ajbdkfb323"},
  {"id2": "fguqge7681"}
  ],
"day" : "Wednesday"
}

或者如果我只想删除整个 "Ref" 对象,我该怎么做?

假设您创建的文档类似于

> Create(Ref(Collection("cls"), "1002"), {data: {Name: "UserName", Ref: [{id: "ajbdkfb323"}, {id: "fguqge7681"}, {id: "chv76aavbb"}], day: "Wednesday"}})
{
  ref: Ref(Collection("cls"), "1002"),
  ts: 1586273769713000,
  data: {
    Name: 'UserName',
    Ref: [
      { id: 'ajbdkfb323' },
      { id: 'fguqge7681' },
      { id: 'chv76aavbb' }
    ],
    day: 'Wednesday'
  }
}

您可以更新 Ref 字段,例如

> Let({
    ref: Ref(Collection("cls"), "1002"),

    dataRef: Select(["data", "Ref"], Get(Var("ref"))),

    dataRefFiltered: Filter(
      Var("dataRef"),
      Lambda("obj", Not(Equals("chv76aavbb", Select("id", Var("obj")))))
    )
  },
  Update(
    Var("ref"),
    { data: { Ref: Var("dataRefFiltered") } }
  )
)

{
  ref: Ref(Collection("cls"), "1002"),
  ts: 1586274149050000,
  data: {
    Name: 'UserName',
    Ref: [ { id: 'ajbdkfb323' }, { id: 'fguqge7681' } ],
    day: 'Wednesday'
  }
}