简体   繁体   中英

Does Datastore (Firestore in Datastore Mode) store entities in order by their key/name?

When a write is performed, does the database write the entities in some kind of order by their key?

For example, if I have written following keys (intentionally keeping the name (1, 7, 3) out of sequence):

["A", "1"]
["A", "7"]
["A", "3"]

Would a query on the Kind A with no filters or ordering return the results as:

["A", "1"]
["A", "3"]
["A", "7"]

Maybe even more to the point if my keys contained a timestamp (milliseconds as the name):

["UserSession", "e4facf67-969d-46f5-b922-390f61beac0a", "UserRecord", "1597872201000"]
["UserSession", "e4facf67-969d-46f5-b922-390f61beac0a", "UserRecord", "1597872207000"]
["UserSession", "e4facf67-969d-46f5-b922-390f61beac0a", "UserRecord", "1597872203000"]

Would a query on

("UserRecord").hasAncestor(["UserSession", "e4facf67-969d-46f5-b922-390f61beac0a"])

return the objects sorted by their name (aka timestamp in milliseconds)?

  • 1597872201000
  • 1597872203000
  • 1597872207000

Yes, Cloud Firestore in Datastore mode does store entities in key order. You can see this from the best practices document which says:

If you assign your own manual numeric ID or custom name to the entities you create, do not use monotonically increasing values

If an application generates large traffic, such sequential numbering could lead to hotspots that impact Datastore mode latency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM