gpt4 book ai didi

java - 在 Firebase Firestore 中保存自定义数据类型

转载 作者:行者123 更新时间:2023-12-02 09:41:29 25 4
gpt4 key购买 nike

我需要将这个类结构存储在 Firebase Firestore 中。

class A {
int i = 3;
}
class B {
A xa = new A();
A ya = new A();
}
class C {
B b = new B();
String name = "hi";
}

C c1 = new C();

我想将值 c1 存储在文档中。
这样做的一种方法是这样的。

db.collection("Cs").document("c1").set({
"b": {
"xa": {
"i": 3,
},
"ya": {
"i": 3,
},
},
"name": "hi",
});

还有另一种方法。

ref1 = db.collection("Cs").document("c1");
ref1.set({"name": "hi"});
ref2 = ref1.collection("B").document("b").collection("A");
ref2.document("xa").set({"i": 3});
ref2.document("xb").set({"i": 3});

谁能告诉我最好的方法是什么?如果还有其他更好的方法,请说明一下吗?

最佳答案

这两种方法之间存在巨大差异。在第一个中,您将这些对象添加到单个文档下,而在第二个中,您使用嵌套集合。

Can anyone tell me what is the best way of doing this.

无论是第一种方法还是第二种方法都更好。我不确定您想要实现什么目标,但一般来说您应该为要执行的查询设计数据库架构。

关于java - 在 Firebase Firestore 中保存自定义数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57035025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com