Chapter 7

  1. In a Cloud Firestore database, what's the difference between a document and a collection? And can a document contain a collection?
    A Collection is a container for a set of documents, where a document is the data itself, expressed in key-value pairs. A document can contain a collection.

  2. Can you name three of the main differences between a SQL and a NoSQL database?
    SQL Databases use the SQL language to perform queries, use of JOINS to express relations between tables, and have a fixed schema. NOSQL stores contain self-describing data, do not require a schema and do not allow using the SQL language to perform queries.

  3. Consider the following code:
docs = await db.collection('favorites') .where('userId', isEqualTo:       uid).getDocuments();

What does this query perform? And which data type is the docs variable?

The getDocuments() asynchronous method retrieves data from the specified collection (in this case favorites), where the userId is equal to the value of the variable uiddocs will contain a QuerySnapshot object.

  1. In a Cloud Firestore database, is it possible to allow data access only to authenticated users? If so, how can you achieve that?
    In a Cloud Firestore database, it is possible to allow data access only to authenticated users by setting a rule. An example is shown here:

application 
service cloud.firestore {
match /databases/{database}/documents { match /{document=**} {
allow read, write: if request.auth.uid != null; } }}
  1. How can you create an instance of a FirebaseAuth class?

    FirebaseAuth is the object that enables the use of Firebase Authentication's methods and properties. You can create an instance of a FirebaseAuth class with the instruction:

final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
  1. Consider the following code:
var result = db.collection('favorites').add(fav.toMap() .then((value) => print(value.documentID)) .catchError((error)=> print (error));

Can you explain what these instructions perform?

A new document is added to the favorites collection. If the task succeeds, the code will print the documentId of the new document in the Debug Console. In case of error, the error itself will be printed.

  1. When would you create a getter method for a property in a class? And how do you write the code to create it?
    A getter method returns a property value of an instance of the class, In this way, you can check or transform values before reading them in your classes. You specify getters by adding the get keyword before the field name. The getter returns a value of the type that you specify: an example is shown here:

int get price {
return _price * 1.2;
}
  1. When do you need a Map object to interact with a Cloud Firestore database?
    When interacting with a Cloud Firestore database, you can pass a Map object to write data to a collection. You can also parse the results of queries into Map objects when retrieving data.

  2. How do you delete a document from a Cloud Firestore database?
    You use the delete() method on a document, as shown in the following code block:

await db.collection('favourites').document(favId).delete();
  1. How do you pass data from one screen to another?
    You need to pass the data in the builder when you create the new route like shown in the following example:

MaterialPageRoute route = MaterialPageRoute(builder: (_) => YourScreen(yourData));
Navigator.push(context, route);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.72.212