תחילת העבודה עם מהדורת Firestore Standard באמצעות ספריות לקוח לשרת

במדריך למתחילים הזה נסביר איך להגדיר את Firestore Enterprise, להוסיף נתונים ואז לראות את הנתונים שהוספתם במסוף Firebase באמצעות ספריות לקוח של שרת ל-C#‎,‏ Go,‏ Java,‏ Node.js,‏ PHP,‏ Python ו-Ruby.

אתם יכולים להשתמש בספריות הלקוח האלה כדי להגדיר סביבות שרת עם הרשאות וגישה מלאה למסד הנתונים.

יצירת מסד נתונים של Cloud Firestore

  1. אם עדיין לא יצרתם פרויקט ב-Firebase: במסוף Firebase, לוחצים על Add project ופועלים לפי ההוראות במסך כדי ליצור פרויקט ב-Firebase או להוסיף שירותי Firebase לפרויקט קיים ב-Google Cloud.

  2. בחלונית שמימין, עוברים אל Databases & Storage > Firestore.

  3. לוחצים על Create database.

  4. בוחרים מיקום למסד הנתונים.

    אם אתם לא יכולים לבחור מיקום, סימן שכבר הגדרתם את המיקום של משאבי ברירת המחדל של Google Cloud בפרויקט. לחלק מהמשאבים בפרויקט (כמו מכונת ברירת המחדל של Cloud Firestore) יש תלות משותפת במיקום, ואפשר להגדיר את המיקום שלהם במהלך יצירת הפרויקט או במהלך הגדרת שירות אחר שחולק את התלות הזו במיקום.

  5. צריך לבחור מצב התחלה ל-Cloud Firestore Security Rules:

    מצב בדיקה

    מתאים לתחילת העבודה עם ספריות הלקוח לנייד ולאינטרנט, אבל מאפשר לכל אחד לקרוא את הנתונים שלכם ולשכתב אותם. אחרי הבדיקה, חשוב לעיין בקטע אבטחת הנתונים.

    כדי להתחיל להשתמש ב-SDK לאינטרנט, לפלטפורמות של Apple או ל-Android, בוחרים במצב בדיקה.

    מצב ייצור

    דוחה את כל פעולות הקריאה והכתיבה מלקוחות בנייד ובאינטרנט. שרתי האפליקציות המאומתים (C#‎,‏ Go,‏ Java,‏ Node.js,‏ PHP,‏ Python או Ruby) עדיין יכולים לגשת למסד הנתונים.

    כדי להתחיל להשתמש בספריית הלקוח של השרת ב-C#‎, ב-Go, ב-Java, ב-Node.js, ב-PHP, ב-Python או ב-Ruby, בוחרים במצב ייצור.

    הקבוצה הראשונית של Cloud Firestore Security Rules תחול על מסד הנתונים שמוגדר כברירת מחדל ב-Cloud Firestore. אם יוצרים כמה מסדי נתונים לפרויקט, אפשר לפרוס את Cloud Firestore Security Rules לכל מסד נתונים.

  6. לוחצים על יצירה.

כשמפעילים את Cloud Firestore, ה-API מופעל גם ב-Cloud API Manager.

הגדרת סביבת הפיתוח

מוסיפים לאפליקציה את התלויות וספריות הלקוח הנדרשות.

Java
  1. מוסיפים את ה-SDK של Firebase לאדמינים לאפליקציה:
    • שימוש ב-Gradle:
      implementation 'com.google.firebase:firebase-admin:9.11.0'
    • שימוש ב-Maven:
      <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>9.11.0</version>
      </dependency>
           
  2. כדי להפעיל את Cloud Firestore עם פרטי הכניסה המתאימים בסביבה שלכם, צריך לפעול לפי ההוראות הבאות.
Python
  1. מוסיפים את ה-SDK של Firebase לאדמינים לאפליקציית Python:
    pip install --upgrade firebase-admin
  2. כדי להפעיל את Cloud Firestore עם פרטי הכניסה המתאימים בסביבה שלכם, צריך לפעול לפי ההוראות הבאות.
Node.js
  1. מוסיפים את ה-SDK של Firebase לאדמינים לאפליקציה:
    npm install firebase-admin --save
  2. כדי להפעיל את Cloud Firestore עם פרטי הכניסה המתאימים בסביבה שלכם, צריך לפעול לפי ההוראות הבאות.
המשך
  1. מוסיפים את SDK של Firebase לאדמינים לאפליקציית Go:
    go get firebase.google.com/go
  2. כדי להפעיל את Cloud Firestore עם פרטי הכניסה המתאימים בסביבה שלכם, צריך לפעול לפי ההוראות הבאות.
PHP
  1. ספריות הלקוח של שרת Cloud Firestore (Java,‏ Node.js,‏ Python,‏ Go,‏ PHP,‏ C#‎ ו-Ruby) משתמשות בApplication Default Credentials לצורך אימות.
    • כדי לבצע אימות מסביבת הפיתוח, מגדירים את משתנה הסביבה GOOGLE_APPLICATION_CREDENTIALS כך שיצביע לקובץ מפתח של חשבון שירות בפורמט JSON. אפשר ליצור קובץ מפתח בדף Credentials בקונסולה לממשקי API.
      export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/keyfile.json"
    • בסביבת הייצור, לא צריך לבצע אימות אם מריצים את האפליקציה ב-App Engine או ב-Compute Engine, באמצעות אותו פרויקט שמשמש ל-Cloud Firestore. אם לא, מגדירים חשבון שירות.
  2. מתקינים ומפעילים את תוסף gRPC ל-PHP, שנדרש כדי להשתמש בספריית הלקוח.
  3. מוסיפים לאפליקציה את ספריית Cloud Firestore PHP:
    composer require google/cloud-firestore
Ruby
  1. ספריות הלקוח של שרת Cloud Firestore (Java,‏ Node.js,‏ Python,‏ Go,‏ PHP,‏ C#‎ ו-Ruby) משתמשות בApplication Default Credentials לצורך אימות.
    • כדי לבצע אימות מסביבת הפיתוח, מגדירים את משתנה הסביבה GOOGLE_APPLICATION_CREDENTIALS כך שיצביע על קובץ מפתח של חשבון שירות בפורמט JSON. אפשר ליצור קובץ מפתח בדף Credentials בקונסולה לממשקי API.
      export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/keyfile.json"
    • בסביבת הייצור, לא צריך לבצע אימות אם מריצים את האפליקציה ב-App Engine או ב-Compute Engine, באמצעות אותו פרויקט שמשמש ל-Cloud Firestore. אם לא, מגדירים חשבון שירות.
  2. מוסיפים את ספריית Cloud Firestore Ruby לאפליקציה ב-Gemfile:
    gem "google-cloud-firestore"
  3. מתקינים את יחסי התלות מהקובץ Gemfile באמצעות:
    bundle install

(אופציונלי) יצירת אב טיפוס ובדיקה באמצעות Firebase Local Emulator Suite

לפני שנסביר איך האפליקציה שלכם כותבת ל-Cloud Firestore וקוראת ממנו, נציג למפתחים לנייד קבוצת כלים שבהם אפשר להשתמש כדי ליצור אב טיפוס ולבדוק את הפונקציונליות של Cloud Firestore: Firebase Local Emulator Suite. אם אתם מנסים מודלים שונים של נתונים, מבצעים אופטימיזציה של כללי האבטחה או מחפשים את הדרך הכי משתלמת לתקשר עם הקצה העורפי, כדאי לעבוד באופן מקומי בלי לפרוס שירותים פעילים.

אמולטור Cloud Firestore הוא חלק מ-Local Emulator Suite, שמאפשר לאפליקציה שלכם לקיים אינטראקציה עם התוכן וההגדרות של מסד הנתונים המדומה, וגם עם משאבי הפרויקט המדומים (פונקציות, מסדי נתונים אחרים וכללי אבטחה).

כדי להשתמש באמולטור של Cloud Firestore, צריך לבצע כמה שלבים:

  1. הוספת שורת קוד להגדרת הבדיקה של האפליקציה כדי להתחבר לאמולטור.
  2. מפעילים את הפקודה firebase emulators:start מהשורש של ספריית הפרויקט המקומית.
  3. מבצעים קריאות מקוד האב טיפוס של האפליקציה באמצעות ערכת SDK של פלטפורמת Cloud Firestore כרגיל.

הדרכה מפורטת שכוללת את Cloud Firestore ו-Cloud Functions זמינה. כדאי גם לעיין במבוא ל-Local Emulator Suite.

מפעילים את Cloud Firestore

מאתחלים מכונה של Cloud Firestore:

Java
ה-SDK של Cloud Firestore מאותחל בדרכים שונות בהתאם לסביבה שלכם. אלה השיטות הכי נפוצות. למידע נוסף, קראו את המאמר הפעלת ה-SDK לאדמינים.
  • הפעלה ב-Google Cloud
    import com.google.auth.oauth2.GoogleCredentials;
    import com.google.cloud.firestore.Firestore;
    
    import com.google.firebase.FirebaseApp;
    import com.google.firebase.FirebaseOptions;
    
    // Use the application default credentials
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
    FirebaseOptions options = new FirebaseOptions.Builder()
        .setCredentials(credentials)
        .setProjectId(projectId)
        .build();
    FirebaseApp.initializeApp(options);
    
    Firestore db = FirestoreClient.getFirestore();
  • הפעלה בשרת שלכם

    כדי להשתמש ב-SDK של Firebase לאדמינים בשרת שלכם, אתם צריכים להשתמש בחשבון שירות.

    נכנסים לדף IAM & admin > Service accounts במסוף Google Cloud. יוצרים מפתח פרטי חדש ושומרים את קובץ ה-JSON. לאחר מכן, משתמשים בקובץ כדי להפעיל את ה-SDK:

    import com.google.auth.oauth2.GoogleCredentials;
    import com.google.cloud.firestore.Firestore;
    
    import com.google.firebase.FirebaseApp;
    import com.google.firebase.FirebaseOptions;
    
    // Use a service account
    InputStream serviceAccount = new FileInputStream("path/to/serviceAccount.json");
    GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
    FirebaseOptions options = new FirebaseOptions.Builder()
        .setCredentials(credentials)
        .build();
    FirebaseApp.initializeApp(options);
    
    Firestore db = FirestoreClient.getFirestore();
  • Python
    ה-SDK של Cloud Firestore מאותחל בדרכים שונות בהתאם לסביבה שלכם. אלה השיטות הכי נפוצות. למידע נוסף, קראו את המאמר אתחול ה-Admin SDK.
  • הפעלה ב-Google Cloud
    import firebase_admin
    from firebase_admin import firestore
    
    # Application Default credentials are automatically created.
    app = firebase_admin.initialize_app()
    db = firestore.client()

    אפשר גם להשתמש בפרטי כניסה קיימים שמוגדרים כברירת מחדל באפליקציה כדי להפעיל את ה-SDK.

    import firebase_admin
    from firebase_admin import credentials
    from firebase_admin import firestore
    
    # Use the application default credentials.
    cred = credentials.ApplicationDefault()
    
    firebase_admin.initialize_app(cred)
    db = firestore.client()
  • הפעלה בשרת שלכם

    כדי להשתמש ב-SDK של Firebase לאדמינים בשרת שלכם, אתם צריכים להשתמש בחשבון שירות.

    נכנסים לדף IAM & admin > Service accounts במסוף Google Cloud. יוצרים מפתח פרטי חדש ושומרים את קובץ ה-JSON. לאחר מכן, משתמשים בקובץ כדי להפעיל את ה-SDK:

    import firebase_admin
    from firebase_admin import credentials
    from firebase_admin import firestore
    
    # Use a service account.
    cred = credentials.Certificate('path/to/serviceAccount.json')
    
    app = firebase_admin.initialize_app(cred)
    
    db = firestore.client()
  • Python

    ה-SDK של Cloud Firestore מאותחל בדרכים שונות בהתאם לסביבה שלכם. אלה השיטות הכי נפוצות. למידע נוסף, קראו את המאמר הפעלת ה-SDK לאדמינים.
  • הפעלה ב-Google Cloud
    import firebase_admin
    from firebase_admin import firestore_async
    
    # Application Default credentials are automatically created.
    app = firebase_admin.initialize_app()
    db = firestore_async.client()

    אפשר גם להשתמש בפרטי כניסה קיימים שמוגדרים כברירת מחדל באפליקציה כדי להפעיל את ה-SDK.

    import firebase_admin
    from firebase_admin import credentials
    from firebase_admin import firestore_async
    
    # Use the application default credentials.
    cred = credentials.ApplicationDefault()
    
    firebase_admin.initialize_app(cred)
    db = firestore_async.client()
  • הפעלה בשרת שלכם

    כדי להשתמש ב-SDK של Firebase לאדמינים בשרת שלכם, אתם צריכים להשתמש בחשבון שירות.

    במסוף Google Cloud, נכנסים לדף IAM & admin > Service accounts. יוצרים מפתח פרטי חדש ושומרים את קובץ ה-JSON. לאחר מכן, משתמשים בקובץ כדי להפעיל את ה-SDK:

    import firebase_admin
    from firebase_admin import credentials
    from firebase_admin import firestore_async
    
    # Use a service account.
    cred = credentials.Certificate('path/to/serviceAccount.json')
    
    app = firebase_admin.initialize_app(cred)
    
    db = firestore_async.client()
  • Node.js
    ה-SDK של Cloud Firestore מאותחל בדרכים שונות בהתאם לסביבה שלכם. אלה השיטות הכי נפוצות. למידע נוסף, קראו את המאמר הפעלת ה-SDK לאדמינים.
    • הפעלה ב-Cloud Functions
      const { initializeApp, applicationDefault, cert } = require('firebase-admin/app');
      const { getFirestore, Timestamp, FieldValue, Filter } = require('firebase-admin/firestore');
      initializeApp();
      
      const db = getFirestore();
      
    • הפעלה ב-Google Cloud
      const { initializeApp, applicationDefault, cert } = require('firebase-admin/app');
      const { getFirestore, Timestamp, FieldValue, Filter } = require('firebase-admin/firestore');
      initializeApp({
        credential: applicationDefault()
      });
      
      const db = getFirestore();
    • הפעלה בשרת שלכם

      כדי להשתמש ב-SDK של Firebase לאדמינים בשרת שלכם (או בכל סביבת Node.js אחרת), אתם צריכים להשתמש בחשבון שירות. במסוף Google Cloud, נכנסים לדף IAM & admin > Service accounts. יוצרים מפתח פרטי חדש ושומרים את קובץ ה-JSON. ואז משתמשים בקובץ כדי להפעיל את ה-SDK:

      const { initializeApp, applicationDefault, cert } = require('firebase-admin/app');
      const { getFirestore, Timestamp, FieldValue, Filter } = require('firebase-admin/firestore');
      const serviceAccount = require('./path/to/serviceAccountKey.json');
      
      initializeApp({
        credential: cert(serviceAccount)
      });
      
      const db = getFirestore();
      
    המשך
    ה-SDK של Cloud Firestore מאותחל בדרכים שונות בהתאם לסביבה שלכם. אלה השיטות הכי נפוצות. למידע נוסף, קראו את המאמר אתחול ה-Admin SDK.
  • הפעלה ב-Google Cloud
    import (
      "log"
    
      firebase "firebase.google.com/go"
      "google.golang.org/api/option"
    )
    
    // Use the application default credentials
    ctx := context.Background()
    conf := &firebase.Config{ProjectID: projectID}
    app, err := firebase.NewApp(ctx, conf)
    if err != nil {
      log.Fatalln(err)
    }
    
    client, err := app.Firestore(ctx)
    if err != nil {
      log.Fatalln(err)
    }
    defer client.Close()
  • הפעלה בשרת שלכם

    כדי להשתמש ב-SDK של Firebase לאדמינים בשרת שלכם, אתם צריכים להשתמש בחשבון שירות.

    במסוף Google Cloud, נכנסים לדף IAM & admin > Service accounts. יוצרים מפתח פרטי חדש ושומרים את קובץ ה-JSON. לאחר מכן, משתמשים בקובץ כדי להפעיל את ה-SDK:

    import (
      "log"
    
      firebase "firebase.google.com/go"
      "google.golang.org/api/option"
    )
    
    // Use a service account
    ctx := context.Background()
    sa := option.WithCredentialsFile("path/to/serviceAccount.json")
    app, err := firebase.NewApp(ctx, nil, sa)
    if err != nil {
      log.Fatalln(err)
    }
    
    client, err := app.Firestore(ctx)
    if err != nil {
      log.Fatalln(err)
    }
    defer client.Close()
  • PHP

    PHP

    מידע נוסף על התקנה ויצירה של לקוח Cloud Firestore זמין במאמר ספריות לקוח של Cloud Firestore.

    use Google\Cloud\Firestore\FirestoreClient;
    
    /**
     * Initialize Cloud Firestore with default project ID.
     */
    function setup_client_create(string $projectId = null)
    {
        // Create the Cloud Firestore client
        if (empty($projectId)) {
            // The `projectId` parameter is optional and represents which project the
            // client will act on behalf of. If not supplied, the client falls back to
            // the default project inferred from the environment.
            $db = new FirestoreClient();
            printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);
        } else {
            $db = new FirestoreClient([
                'projectId' => $projectId,
            ]);
            printf('Created Cloud Firestore client with project ID: %s' . PHP_EOL, $projectId);
        }
    }
    C#‎

    C#‎

    מידע נוסף על התקנה ויצירה של לקוח Cloud Firestore זמין במאמר ספריות לקוח של Cloud Firestore.

    FirestoreDb db = FirestoreDb.Create(project);
    Console.WriteLine("Created Cloud Firestore client with project ID: {0}", project);
    Ruby
    require "google/cloud/firestore"
    
    # The `project_id` parameter is optional and represents which project the
    # client will act on behalf of. If not supplied, the client falls back to the
    # default project inferred from the environment.
    firestore = Google::Cloud::Firestore.new project_id: project_id
    
    puts "Created Cloud Firestore client with given project ID."

    הוספת נתונים

    ב-Cloud Firestore הנתונים מאוחסנים במסמכים, שמאוחסנים באוספים. Cloud Firestore יוצר אוספים ומסמכים באופן משתמע בפעם הראשונה שמוסיפים נתונים למסמך. אין צורך ליצור אוספים או מסמכים באופן מפורש.

    יוצרים אוסף חדש ומסמך באמצעות הקוד לדוגמה הבא.

    Java
    DocumentReference docRef = db.collection("users").document("alovelace");
    // Add document data  with id "alovelace" using a hashmap
    Map<String, Object> data = new HashMap<>();
    data.put("first", "Ada");
    data.put("last", "Lovelace");
    data.put("born", 1815);
    //asynchronously write data
    ApiFuture<WriteResult> result = docRef.set(data);
    // ...
    // result.get() blocks on response
    System.out.println("Update time : " + result.get().getUpdateTime());
    Python
    doc_ref = db.collection("users").document("alovelace")
    doc_ref.set({"first": "Ada", "last": "Lovelace", "born": 1815})

    Python

    doc_ref = db.collection("users").document("alovelace")
    await doc_ref.set({"first": "Ada", "last": "Lovelace", "born": 1815})
    Node.js
    const docRef = db.collection('users').doc('alovelace');
    
    await docRef.set({
      first: 'Ada',
      last: 'Lovelace',
      born: 1815
    });
    המשך
    _, _, err := client.Collection("users").Add(ctx, map[string]interface{}{
    	"first": "Ada",
    	"last":  "Lovelace",
    	"born":  1815,
    })
    if err != nil {
    	log.Fatalf("Failed adding alovelace: %v", err)
    }
    PHP

    PHP

    מידע נוסף על התקנה ויצירה של לקוח Cloud Firestore זמין במאמר ספריות לקוח של Cloud Firestore.

    $docRef = $db->collection('samples/php/users')->document('alovelace');
    $docRef->set([
        'first' => 'Ada',
        'last' => 'Lovelace',
        'born' => 1815
    ]);
    printf('Added data to the lovelace document in the users collection.' . PHP_EOL);
    C#‎
    DocumentReference docRef = db.Collection("users").Document("alovelace");
    Dictionary<string, object> user = new Dictionary<string, object>
    {
        { "First", "Ada" },
        { "Last", "Lovelace" },
        { "Born", 1815 }
    };
    await docRef.SetAsync(user);
    Ruby
    doc_ref = firestore.doc "#{collection_path}/alovelace"
    
    doc_ref.set(
      {
        first: "Ada",
        last:  "Lovelace",
        born:  1815
      }
    )
    
    puts "Added data to the alovelace document in the users collection."

    עכשיו צריך להוסיף עוד מסמך לאוסף users. שימו לב שהמסמך הזה כולל צמד מפתח/ערך (שם אמצעי) שלא מופיע במסמך הראשון. מסמכים באוסף יכולים להכיל קבוצות שונות של מידע.

    Java
    DocumentReference docRef = db.collection("users").document("aturing");
    // Add document data with an additional field ("middle")
    Map<String, Object> data = new HashMap<>();
    data.put("first", "Alan");
    data.put("middle", "Mathison");
    data.put("last", "Turing");
    data.put("born", 1912);
    
    ApiFuture<WriteResult> result = docRef.set(data);
    System.out.println("Update time : " + result.get().getUpdateTime());
    Python
    doc_ref = db.collection("users").document("aturing")
    doc_ref.set({"first": "Alan", "middle": "Mathison", "last": "Turing", "born": 1912})

    Python

    doc_ref = db.collection("users").document("aturing")
    await doc_ref.set(
        {"first": "Alan", "middle": "Mathison", "last": "Turing", "born": 1912}
    )
    Node.js
    const aTuringRef = db.collection('users').doc('aturing');
    
    await aTuringRef.set({
      'first': 'Alan',
      'middle': 'Mathison',
      'last': 'Turing',
      'born': 1912
    });
    המשך
    _, _, err = client.Collection("users").Add(ctx, map[string]interface{}{
    	"first":  "Alan",
    	"middle": "Mathison",
    	"last":   "Turing",
    	"born":   1912,
    })
    if err != nil {
    	log.Fatalf("Failed adding aturing: %v", err)
    }
    PHP

    PHP

    מידע נוסף על התקנה ויצירה של לקוח Cloud Firestore זמין במאמר ספריות לקוח של Cloud Firestore.

    $docRef = $db->collection('samples/php/users')->document('aturing');
    $docRef->set([
        'first' => 'Alan',
        'middle' => 'Mathison',
        'last' => 'Turing',
        'born' => 1912
    ]);
    printf('Added data to the aturing document in the users collection.' . PHP_EOL);
    C#‎
    DocumentReference docRef = db.Collection("users").Document("aturing");
    Dictionary<string, object> user = new Dictionary<string, object>
    {
        { "First", "Alan" },
        { "Middle", "Mathison" },
        { "Last", "Turing" },
        { "Born", 1912 }
    };
    await docRef.SetAsync(user);
    Ruby
    doc_ref = firestore.doc "#{collection_path}/aturing"
    
    doc_ref.set(
      {
        first:  "Alan",
        middle: "Mathison",
        last:   "Turing",
        born:   1912
      }
    )
    
    puts "Added data to the aturing document in the users collection."

    קריאת נתונים

    כדי לוודא במהירות שהוספתם נתונים ל-Cloud Firestore, אתם יכולים להשתמש בכלי להצגת נתונים במסוף Firebase.

    אפשר גם להשתמש ב-method‏ "get" כדי לאחזר את כל האוסף.

    Java
    // asynchronously retrieve all users
    ApiFuture<QuerySnapshot> query = db.collection("users").get();
    // ...
    // query.get() blocks on response
    QuerySnapshot querySnapshot = query.get();
    List<QueryDocumentSnapshot> documents = querySnapshot.getDocuments();
    for (QueryDocumentSnapshot document : documents) {
      System.out.println("User: " + document.getId());
      System.out.println("First: " + document.getString("first"));
      if (document.contains("middle")) {
        System.out.println("Middle: " + document.getString("middle"));
      }
      System.out.println("Last: " + document.getString("last"));
      System.out.println("Born: " + document.getLong("born"));
    }
    Python
    users_ref = db.collection("users")
    docs = users_ref.stream()
    
    for doc in docs:
        print(f"{doc.id} => {doc.to_dict()}")

    Python

    users_ref = db.collection("users")
    docs = users_ref.stream()
    
    async for doc in docs:
        print(f"{doc.id} => {doc.to_dict()}")
    Node.js
    const snapshot = await db.collection('users').get();
    snapshot.forEach((doc) => {
      console.log(doc.id, '=>', doc.data());
    });
    המשך
    iter := client.Collection("users").Documents(ctx)
    for {
    	doc, err := iter.Next()
    	if err == iterator.Done {
    		break
    	}
    	if err != nil {
    		log.Fatalf("Failed to iterate: %v", err)
    	}
    	fmt.Println(doc.Data())
    }
    PHP

    PHP

    מידע נוסף על התקנה ויצירה של לקוח Cloud Firestore זמין במאמר ספריות לקוח של Cloud Firestore.

    $usersRef = $db->collection('samples/php/users');
    $snapshot = $usersRef->documents();
    foreach ($snapshot as $user) {
        printf('User: %s' . PHP_EOL, $user->id());
        printf('First: %s' . PHP_EOL, $user['first']);
        if (!empty($user['middle'])) {
            printf('Middle: %s' . PHP_EOL, $user['middle']);
        }
        printf('Last: %s' . PHP_EOL, $user['last']);
        printf('Born: %d' . PHP_EOL, $user['born']);
        printf(PHP_EOL);
    }
    printf('Retrieved and printed out all documents from the users collection.' . PHP_EOL);
    C#‎
    CollectionReference usersRef = db.Collection("users");
    QuerySnapshot snapshot = await usersRef.GetSnapshotAsync();
    foreach (DocumentSnapshot document in snapshot.Documents)
    {
        Console.WriteLine("User: {0}", document.Id);
        Dictionary<string, object> documentDictionary = document.ToDictionary();
        Console.WriteLine("First: {0}", documentDictionary["First"]);
        if (documentDictionary.ContainsKey("Middle"))
        {
            Console.WriteLine("Middle: {0}", documentDictionary["Middle"]);
        }
        Console.WriteLine("Last: {0}", documentDictionary["Last"]);
        Console.WriteLine("Born: {0}", documentDictionary["Born"]);
        Console.WriteLine();
    }
    Ruby
    users_ref = firestore.col collection_path
    users_ref.get do |user|
      puts "#{user.document_id} data: #{user.data}."
    end

    השלבים הבאים

    כדי להעמיק את הידע שלכם, אתם יכולים לקרוא על הנושאים הבאים: