[docs] Add some basic Firestore docs for launch
This commit is contained in:
parent
51074efdca
commit
5e3ac2491d
@ -57,6 +57,7 @@ All in all, RNFirebase provides much faster performance (~2x) over the web SDK a
|
|||||||
| **Cloud Messaging (FCM)** | ✅ | ✅ | ✅ |**?**|
|
| **Cloud Messaging (FCM)** | ✅ | ✅ | ✅ |**?**|
|
||||||
| **Crash Reporting** | ✅ | ✅ | ✅ | ❌ |
|
| **Crash Reporting** | ✅ | ✅ | ✅ | ❌ |
|
||||||
| **Dynamic Links** | ❌ | ❌ | ❌ | ❌ |
|
| **Dynamic Links** | ❌ | ❌ | ❌ | ❌ |
|
||||||
|
| **Firestore** | ❌ | ❌ | ✅ | ❌ |
|
||||||
| **Invites** | ❌ | ❌ | ❌ | ❌ |
|
| **Invites** | ❌ | ❌ | ❌ | ❌ |
|
||||||
| **Performance Monitoring** | ✅ | ✅ | ✅ | ❌ |
|
| **Performance Monitoring** | ✅ | ✅ | ✅ | ❌ |
|
||||||
| **Realtime Database** | ✅ | ✅ | ✅ | ✅ |
|
| **Realtime Database** | ✅ | ✅ | ✅ | ✅ |
|
||||||
|
@ -46,6 +46,7 @@ All in all, RNFirebase provides much faster performance (~2x) over the web SDK a
|
|||||||
| **Cloud Messaging (FCM)** | ✅ | ✅ | ✅ |**?**|
|
| **Cloud Messaging (FCM)** | ✅ | ✅ | ✅ |**?**|
|
||||||
| **Crash Reporting** | ✅ | ✅ | ✅ | ❌ |
|
| **Crash Reporting** | ✅ | ✅ | ✅ | ❌ |
|
||||||
| **Dynamic Links** | ❌ | ❌ | ❌ | ❌ |
|
| **Dynamic Links** | ❌ | ❌ | ❌ | ❌ |
|
||||||
|
| **Firestore** | ❌ | ❌ | ✅ | ❌ |
|
||||||
| **Invites** | ❌ | ❌ | ❌ | ❌ |
|
| **Invites** | ❌ | ❌ | ❌ | ❌ |
|
||||||
| **Performance Monitoring** | ✅ | ✅ | ✅ | ❌ |
|
| **Performance Monitoring** | ✅ | ✅ | ✅ | ❌ |
|
||||||
| **Realtime Database** | ✅ | ✅ | ✅ | ✅ |
|
| **Realtime Database** | ✅ | ✅ | ✅ | ✅ |
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
- [Cloud Messaging](/modules/cloud-messaging)
|
- [Cloud Messaging](/modules/cloud-messaging)
|
||||||
- [Crash Reporting](/modules/crash)
|
- [Crash Reporting](/modules/crash)
|
||||||
- [Database](/modules/database)
|
- [Database](/modules/database)
|
||||||
|
- [Firestore (Beta)](/modules/firestore)
|
||||||
- [Remote Config](/modules/config)
|
- [Remote Config](/modules/config)
|
||||||
- [Storage](/modules/storage)
|
- [Storage](/modules/storage)
|
||||||
- [Transactions](/modules/transactions)
|
- [Transactions](/modules/transactions)
|
||||||
|
@ -53,6 +53,7 @@ dependencies {
|
|||||||
compile "com.google.firebase:firebase-config:11.2.0"
|
compile "com.google.firebase:firebase-config:11.2.0"
|
||||||
compile "com.google.firebase:firebase-crash:11.2.0"
|
compile "com.google.firebase:firebase-crash:11.2.0"
|
||||||
compile "com.google.firebase:firebase-database:11.2.0"
|
compile "com.google.firebase:firebase-database:11.2.0"
|
||||||
|
compile "com.google.firebase:firebase-firestore:11.2.0"
|
||||||
compile "com.google.firebase:firebase-messaging:11.2.0"
|
compile "com.google.firebase:firebase-messaging:11.2.0"
|
||||||
compile "com.google.firebase:firebase-perf:11.2.0"
|
compile "com.google.firebase:firebase-perf:11.2.0"
|
||||||
compile "com.google.firebase:firebase-storage:11.2.0"
|
compile "com.google.firebase:firebase-storage:11.2.0"
|
||||||
@ -88,6 +89,7 @@ import io.invertase.firebase.auth.RNFirebaseAuthPackage; // Firebase Auth
|
|||||||
import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage; // Firebase Remote Config
|
import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage; // Firebase Remote Config
|
||||||
import io.invertase.firebase.crash.RNFirebaseCrashPackage; // Firebase Crash Reporting
|
import io.invertase.firebase.crash.RNFirebaseCrashPackage; // Firebase Crash Reporting
|
||||||
import io.invertase.firebase.database.RNFirebaseDatabasePackage; // Firebase Realtime Database
|
import io.invertase.firebase.database.RNFirebaseDatabasePackage; // Firebase Realtime Database
|
||||||
|
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage; // Firebase Firestore
|
||||||
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; // Firebase Cloud Messaging
|
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; // Firebase Cloud Messaging
|
||||||
import io.invertase.firebase.perf.RNFirebasePerformancePackage; // Firebase Performance
|
import io.invertase.firebase.perf.RNFirebasePerformancePackage; // Firebase Performance
|
||||||
import io.invertase.firebase.storage.RNFirebaseStoragePackage; // Firebase Storage
|
import io.invertase.firebase.storage.RNFirebaseStoragePackage; // Firebase Storage
|
||||||
@ -107,6 +109,7 @@ public class MainApplication extends Application implements ReactApplication {
|
|||||||
new RNFirebaseRemoteConfigPackage(),
|
new RNFirebaseRemoteConfigPackage(),
|
||||||
new RNFirebaseCrashPackage(),
|
new RNFirebaseCrashPackage(),
|
||||||
new RNFirebaseDatabasePackage(),
|
new RNFirebaseDatabasePackage(),
|
||||||
|
new RNFirebaseFirestorePackage(),
|
||||||
new RNFirebaseMessagingPackage(),
|
new RNFirebaseMessagingPackage(),
|
||||||
new RNFirebasePerformancePackage(),
|
new RNFirebasePerformancePackage(),
|
||||||
new RNFirebaseStoragePackage()
|
new RNFirebaseStoragePackage()
|
||||||
|
@ -69,6 +69,7 @@ pod 'Firebase/Auth'
|
|||||||
pod 'Firebase/Crash'
|
pod 'Firebase/Crash'
|
||||||
pod 'Firebase/Database'
|
pod 'Firebase/Database'
|
||||||
pod 'Firebase/DynamicLinks'
|
pod 'Firebase/DynamicLinks'
|
||||||
|
pod 'Firestore'
|
||||||
pod 'Firebase/Messaging'
|
pod 'Firebase/Messaging'
|
||||||
pod 'Firebase/RemoteConfig'
|
pod 'Firebase/RemoteConfig'
|
||||||
pod 'Firebase/Storage'
|
pod 'Firebase/Storage'
|
||||||
|
171
docs/modules/firestore.md
Normal file
171
docs/modules/firestore.md
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
|
||||||
|
# Firestore (Beta)
|
||||||
|
|
||||||
|
RNFirebase mimics the [Firestore Web SDK](https://firebase.google.com/docs/database/web/read-and-write), whilst
|
||||||
|
providing support for devices in low/no data connection state.
|
||||||
|
|
||||||
|
All Firestore operations are accessed via `firestore()`.
|
||||||
|
|
||||||
|
Please note that Persistence (offline support) is enabled by default with Firestore on iOS and Android.
|
||||||
|
|
||||||
|
## Add and Manage Data
|
||||||
|
|
||||||
|
### Collections
|
||||||
|
|
||||||
|
Read information about a collection example:
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.collection('posts')
|
||||||
|
.get()
|
||||||
|
.then(querySnapshot => {
|
||||||
|
// Access all the documents in the collection
|
||||||
|
const docs = querySnapshot.docs;
|
||||||
|
// Access the list of document changes for the collection
|
||||||
|
const changes = querySnapshot.docChanges;
|
||||||
|
// Loop through the documents
|
||||||
|
querySnapshot.forEach((doc) => {
|
||||||
|
const value = doc.data();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Add to a collection example (generated ID):
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.collection('posts')
|
||||||
|
.add({
|
||||||
|
title: 'Amazing post',
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// Document added to collection and ID generated
|
||||||
|
// Will have path: `posts/{generatedId}`
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Add to a collection example (manual ID):
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.collection('posts')
|
||||||
|
.doc('post1')
|
||||||
|
.set({
|
||||||
|
title: 'My awesome post',
|
||||||
|
content: 'Some awesome content',
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// Document added to collection with path: `posts/post1`
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Documents
|
||||||
|
|
||||||
|
There are multiple ways to read a document. The following are equivalent examples:
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.doc('posts/posts1')
|
||||||
|
.get((documentSnapshot) => {
|
||||||
|
const value = documentSnapshot.data();
|
||||||
|
});
|
||||||
|
|
||||||
|
firebase.firestore()
|
||||||
|
.collection('posts')
|
||||||
|
.doc('posts1')
|
||||||
|
.get((documentSnapshot) => {
|
||||||
|
const value = documentSnapshot.data();
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a document example:
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.doc('posts/posts1')
|
||||||
|
.set({
|
||||||
|
title: 'My awesome post',
|
||||||
|
content: 'Some awesome content',
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// Document created
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Updating a document example:
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.doc('posts/posts1')
|
||||||
|
.update({
|
||||||
|
title: 'My awesome post',
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// Document created
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Deleting a document example:
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.doc('posts/posts1')
|
||||||
|
.delete()
|
||||||
|
.then(() => {
|
||||||
|
// Document deleted
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Batching document updates
|
||||||
|
|
||||||
|
Writes, updates and deletes to documents can be batched and committed atomically as follows:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const ayRef = firebase.firestore().doc('places/AY');
|
||||||
|
const lRef = firebase.firestore().doc('places/LON');
|
||||||
|
const nycRef = firebase.firestore().doc('places/NYC');
|
||||||
|
const sfRef = firebase.firestore().doc('places/SF');
|
||||||
|
|
||||||
|
firebase.firestore()
|
||||||
|
.batch()
|
||||||
|
.set(ayRef, { name: 'Aylesbury' })
|
||||||
|
.set(lRef, { name: 'London' })
|
||||||
|
.set(nycRef, { name: 'New York City' })
|
||||||
|
.set(sfRef, { name: 'San Francisco' })
|
||||||
|
.update(nycRef, { population: 1000000 })
|
||||||
|
.update(sfRef, { name: 'San Fran' })
|
||||||
|
.set(lRef, { population: 3000000 }, { merge: true })
|
||||||
|
.delete(ayRef)
|
||||||
|
.commit()
|
||||||
|
.then(() => {
|
||||||
|
// Would end up with three documents in the collection: London, New York City and San Francisco
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Transactions
|
||||||
|
|
||||||
|
Coming soon
|
||||||
|
|
||||||
|
## Realtime Updates
|
||||||
|
|
||||||
|
### Collections
|
||||||
|
|
||||||
|
Listen to collection updates example:
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.collection('cities')
|
||||||
|
.where('state', '==', 'CA')
|
||||||
|
.onSnapshot((querySnapshot) => {
|
||||||
|
querySnapshot.forEach((doc) => {
|
||||||
|
// DocumentSnapshot available
|
||||||
|
})
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
The snapshot handler will receive a new query snapshot every time the query results change (that is, when a document is added, removed, or modified).
|
||||||
|
|
||||||
|
### Documents
|
||||||
|
|
||||||
|
Listen to document updates example:
|
||||||
|
```javascript
|
||||||
|
firebase.firestore()
|
||||||
|
.doc('posts/post1')
|
||||||
|
.onSnapshot((documentSnapshot) => {
|
||||||
|
// DocumentSnapshot available
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
The snapshot handler will receive the current contents of the document, and any subsequent changes to the document.
|
Loading…
x
Reference in New Issue
Block a user