Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of a collection and a document of firebase in sql?

My question is that what is the equivalent of a collection and a document of firebase in other databases like SQL or MongoDB,

I know that there is a table in SQL but what is the equivalent of the following path:

/collection/document/collection

I mean that can I add a table(collection) to a document in SQL or mongoose and what is the architecture of that?

Thanks,

like image 999
not working Avatar asked Jan 26 '23 10:01

not working


2 Answers

A Firestore collection is roughly equivalent to a SQL table.

A Firestore document is roughly equivalent to a SQL row.

Nested subcollections in Firestore don't have a direct SQL equivalent. You would just use another table for that. Since tables can't be "nested" in SQL, it has to exist at the top level along with all the others.

like image 164
Doug Stevenson Avatar answered Jan 27 '23 23:01

Doug Stevenson


The closest equivalents to collections and documents in a relation database would be a table and a row. But as you've found, Firestore allows nesting collections under documents again, and there's no way to nest tables under rows in relational databases.

What you'd do in a relational database is add a parent key to the rows that are under another record. So if you have a collection and a subcollection in Firestore, you could for example model that as two separate tables in a relational database, where you then give each row/record in subcollection a foreign key with the ID of the collection record that it falls under.

like image 43
Frank van Puffelen Avatar answered Jan 28 '23 01:01

Frank van Puffelen