Mikael Lirbank
Mikael Lirbank17mo ago

I am curious how does `db get ` know

I am curious, how does db.get() know which table to look in? What's the science behind it? Or are all docs just saved in the same table, so to speak, on your servers? I was imagining you use something similar to a shard key or sumething maybe? Or a seeded random generator for the IDs?
3 Replies
RJ
RJ17mo ago
I believe the IDs encode the table name in them!
lee
lee17mo ago
IDs encoding the table name is a good way to think of it, although it's not exactly a table name. This level of indirection allows ids to be roughly the same length, and also allows table deletions. If you delete a table and create a new one with the same name, ids from the old table are separate from ids in the new table. The downside is that you can only get the table name from an ID when you have a db, which is what db.normalizeId does

Did you find this page helpful?