Reputation: 3127
I am new to NoSQL and I'm trying to figure out a good way to represent my data. I have a series of workers that need to request vacations via mobile app.
When I try to write a Firebase query with Flutter, I can do this:
Firestore.instance
.collection("ferie_permessi")
.document("[email protected]")
.snapshot();
It works but there are two main errors:
[email protected]
as document ID as it already esists;I'm quite sure that this structure isn't good at all. Each worker needs to have 2 lists: vacations
and other
. What is wrong?
My guess is that I should move [email protected]
together with vacations
and other
so that I can make a query of this kind:
Firestore.instance
.collection("ferie_permessi")
.where("user", "==", "[email protected])
.snapshot();
But now the id? Is an automatic one good?
Upvotes: 0
Views: 127
Reputation: 837
I had a chance to recently explore creating an app using a firebase-firestore. A couple of things will help here:
id
is good since it is unique, for example, you can have a collections vacation_requests
, users
you can then use that user_id
as a document in vaccation_requests
-> user_id
-> vacations
, instead of using email as a document key.Or
You can do it like this collections users
, vacation_requests
, and requests
.
users
.requests
with from
and to
dates.vaccation_requests
.Hope this helps!
Upvotes: 1