我是firebase的新手.

我该如何通过以下规则?

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

I've tried to change the rule to below,

{
  "rules": 
   {
    ".read": true,
    ".write": true,
   }
}

but there's an error of

mismatched input '{' expecting {'function', 'service', 'syntax'}

Below is the db structure.

db structure

目前,这是我的代码(一直拒绝返回权限):

    // [START initialize_database_ref]
    mDatabase = FirebaseDatabase.getInstance().reference
    // [END initialize_database_ref]

    val result = HashMap<String, Any> ()
    result.put("timestamp", getCurrentTime())
    result.put("user_id", USER_ID)
    result.put("x_position", -1)
    result.put("y_position", -1)

    mDatabase!!.ref.child("raw data").child("Z9QD79lDzP7MpD6feWeJ").setValue(result).addOnFailureListener(object : OnFailureListener {
        override fun onFailure(@NonNull e: Exception) {
            Log.d("firebase", e.localizedMessage)
        }
    })

Any help would be appreciated! Thanks :)

推荐答案

I was able to solve the problem by switching from Cloud Firestore to Realtime Database, and then changing the rule. (After I've changed this, there was no more error showing!) enter image description here

Kotlin相关问答推荐

在intellij中使用kotlin符号和floordiv

Kotlin中一个接口的实现问题

处理合成层次 struct 中的深层按钮以切换视图

Kotlin扩展函数未调用Hibernate/JPA中的重写函数

如何在 Spring Boot 3 中为内部类提供运行时提示

如何从 var list 或可变列表中获取列表流

JetPack Compose:添加点击持续时间

如何使用子变量在 Kotlin 中初始化父级

如何将字符串格式化为电话号码kotlin算法

如何在kotlin中使用协程每秒调用一个函数

Kotlin 代码是如何编译成原生代码的?

如何使用 gradle 脚本 Kotlin 构建文件构建可运行的 ShadowJar?

在 Kotlin 中实现 (/inherit/~extend) 注解

如果 Maybe 完成,则从其他来源将 Maybe 转换为 Single

如何将vararg转换为list?

Android EditText 协程go 抖操作符,如 RxJava

Kotlin中的Memoization功能

具有泛型param的Kotlin抽象类和使用类型param的方法

通过在 kotlin-gradle 中使用子项目Unresolved reference: implementation

从另一个列表创建一个列表