【发布时间】:2020-09-02 13:01:13
【问题描述】:
我在应用程序中将数据保存到 Firestore。在代码中,它看起来像这样:
db.collection("flowers")
.document()
.setData(["Name":self.flowerName,
"Cup width":self.cupWidth,
"Cup height":self.cupHeight,
"Stem length":self.stemLength,
"Leaf width":self.leafWidth,
"Leaf length":self.leafLength])
但在 Firestore 中它看起来像这样:
Cup height: "1"
Cup width: "1"
Leaf length: "1"
Leaf width: "1"
Name: "Rose"
Stem length: "1"
我希望它们以与在应用程序中传输相同的方式保存在数据库中。我猜它们在数据库中按字母顺序排序,但可以更改吗?我在文档中查找了任何信息,但没有找到任何信息。
【问题讨论】:
-
你使用字典,它是无序容器。
-
为什么要它们以特定顺序保存在数据库中?阅读时,您可以按您喜欢的任何顺序访问这些字段。控制台按字典顺序显示所有数据,正如@frankvanpuffelen 在他的回答中提到的那样,也正如你提到的那样,但这似乎不是你要问的。如果您能澄清您的要求,我们或许可以提供解决方案。
标签: swift firebase google-cloud-firestore swiftui