-
-
Notifications
You must be signed in to change notification settings - Fork 5
Firestore Get Started
The contents of this page are based on the original Firebase Documentation
This quickstart shows you how to set up Cloud Firestore, add data, then view the data you just added in the Firebase console.
- Open the Firebase Console and create a new project.
- In the Database section, click the Get Started button for Cloud Firestore.
- Select a starting mode for your Cloud Firestore Security Rules:
Test mode
Good for getting started with the mobile and web client libraries, but allows anyone to read and overwrite your data. After testing, make sure to see the Secure your data section.
To get started with the Web, IOS, or Android SDK, select test mode.
Locked mode
Denies all reads and writes from mobile and web clients. Your authenticated application servers (C#, Go, Java, Node.js, PHP, or Python) can still access your database.
To get started with the C#, Go, Java, Node.js, PHP, or Python server client library, select locked mode.
- Click Enable.
Cloud Firestore and App Engine: You can't use both Cloud Firestore and Cloud Datastore in the same project, which might affect apps using App Engine. Try using Cloud Firestore with a different project.
Initialize an instance of Cloud Firestore:
import com.tuarua.firebase.FirestoreANE;
private var db:FirestoreANE;
db = FirestoreANE.firestore;
Cloud Firestore stores data in Documents, which are stored in Collections. Cloud Firestore creates collections and documents implicitly the first time you add data to the document. You do not need to explicitly create collections or documents.
Create a new collection and a document using the following example code.
// Add a new document with a generated ID
var ref:DocumentReference;
ref = db.collection("users").addDocument({
"first": "Ada",
"last": "Lovelace",
"born": 1815
}, function (path:String, error:FirestoreError):void {
if (error) {
trace("Error adding document: " + error);
} else {
trace("Document added with ID: " + ref.id);
}
});
Now add another document to the users collection. Notice that this document includes a key-value pair (middle name) that does not appear in the first document. Documents in a collection can contain different sets of information.
// Add a second document with a generated ID.
var ref:DocumentReference;
ref = db.collection("users").addDocument({
"first": "Alan",
"middle": "Mathison",
"last": "Turing",
"born": 1912
}, function (path:String, error:FirestoreError):void {
if (error) {
trace("Error adding document: " + error);
} else {
trace("Document added with ID: " + ref.id);
}
});
To quickly verify that you've added data to Cloud Firestore, use the data viewer in the Firebase console.
You can also use the getDocuments method to retrieve the entire collection.
db.collection("users").getDocuments(function (snapshot:QuerySnapshot, error:FirestoreError):void {
if (error) {
trace("Error getting documents: " + error);
}else {
for each (var document:DocumentSnapshot in snapshot.documents) {
trace(document.id)
}
}
});
Use Firebase Authentication and Cloud Firestore Security Rules to secure your data in Cloud Firestore.
Here are some basic rule sets you can use to get started. You can modify your security rules in the Rules tab of the console.
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
// Deny read/write access to all users under any conditions
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
// Allow read/write access to all users under any conditions
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.
Project setup
Analytics
Authentication
Dynamic Links
Google Sign In
Firestore
- Configuring the ANE
- Get Started
- Add and Manage Data
- Query Data
- Get Data
- Get Realtime Updates
- Perform Simple and Compound Queries
- Order and Limit Data
- Paginate Data
Messaging
One Signal
Performance
Remote Config
Storage
- Configuring the ANE
- Get Started
- Create a Reference
- Upload Files
- Download Files
- Use File Metadata
- Delete Files
Crashlytics
Vision
- Detect faces
- Scan barcodes
- Label images
- Recognize landmarks
- Natural Language
- Custom Models
External Links