无法使用“期间”更新/删除Firestore字段在名字里 [英] Cannot update/delete Firestore field with "period" in the name

查看:71
本文介绍了无法使用“期间”更新/删除Firestore字段在名字里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新/删除Firestore文档中的字段,但是在尝试更新/删除它们时,名称中具有句点的字段似乎无声地失败。我有句点的原因是我使用URL作为对象中的键,我觉得这是一个半常见的用例。

I'm trying to update/delete a fields in a Firestore document, but the fields that have a "period" in the name seem to be silently failing when trying to update/delete them. The reason I have periods is that I'm using URLs as the keys in the object, I feel this is a semi-common use case.

示例:

首先创建文档(这很好)

First create the document (this works fine)

db.collection("data").doc("temp").set({
  helloworld: {
      key1: 'foo'
  },
  hello.world: {
      key1: 'bar'
  }
})

如果你试图删除没有句点的元素,它工作正常。

If you try to delete the element without the period, it works fine.

db.collection("data").doc("temp").update({
    helloworld: firebase.firestore.FieldValue.delete()
})
// Value is Deleted

如果您尝试删除没有句点的元素,它就不会做任何事情。

If you try to delete the element without the period, it doesn't do anything.

db.collection("data").doc("temp").update({
    hello.world: firebase.firestore.FieldValue.delete()
})
// Nothing Happens!

我也试过

let u = {}
u['hello.world'] = firebase.firestore.FieldValue.delete()
db.collection("data").doc("temp").update(u)
// Nothing Happens!

这是一个错误吗?是否支持字段名称中的句点?看起来很奇怪我可以创建元素但不能删除它。

Is this a bug? Are periods in field names supported? It seems strange I can create the element but not delete it.

推荐答案

当你使用句点时,你需要用引号括起来更新或删除时的名称如:

You need to wrap it in quotes when you use periods in the name on an update or delete like:

db.collection("data").doc("temp").update({
  "hello.world": firebase.firestore.FieldValue.delete()
})

或动态名称:

[`hello.${world}`]: firebase.firestore.FieldValue.delete()

这篇关于无法使用“期间”更新/删除Firestore字段在名字里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆