Home > Enterprise >  What is the best way to retrieve good answer from Firestore in a Quiz app to avoid that a user know
What is the best way to retrieve good answer from Firestore in a Quiz app to avoid that a user know

Time:04-27

I read multiple Stack Overflow posts speaking about how to store data for a quiz app. They say that questions and good answers shouldn't be in the same document as a user can know the good answer before responding to a question. I want to avoid that. So I put good answers and questions in separate collections and documents.

The problem is in my application, when can I retrieve the good answers for the questions to avoid users to know the good answer before they click on an answer?

  • I think about when the user presses on an answer, the application starts a query to Firestore to retrieve the good answer for the question and once the data is loaded, compare it with the user answer. I fear this idea because when the user presses the button he will need to wait for the data to load and I think the user will be boring. I don't see another solution. I'm open to any suggestions.

Here is my Firestore data architecture:

enter image description here enter image description here enter image description here enter image description here

CodePudding user response:

I want to avoid that. So I put good answers and questions in separate collections and documents.

That's not a bad idea but it's a little expensive since everything in Firestore is about the number of reads and writes you perform.

The problem is in my application, when can I retrieve the good answers for the questions to avoid users to know the good answer before they click on an answer?

You can create an additional query to get the correct answers, right when you display the question. In this way, you will know the answers beforehand. But in my opinion, it makes more sense to have all the data in a single document. In this way, you only have to pay for a single read.

I fear this idea because when the user presses the button he will need to wait for the data to load and I think the user will be boring.

Reading a document is an asynchronous operation. So yes, you have to wait for the data, but as long as you read small size documents, the read operation should be really fast.

  • Related