Skip to content

Instantly share code, notes, and snippets.

// Retrieve cities from California
db.collection("cities").where("state", "==", "CA")
.onSnapshot(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// binded to the UI
allItems.push(doc.data().name);
});
});
// Retrieve cities from Colorado
<!-- list of California cities goes here -->
<ul>
...
</ul>
<!-- list of Colerado cities goes here -->
<ul
...
</ul>
// Query for California
var californiaRef = citiesRef.where("state", "==", "CA");
// Query for Colorado
var coloradoRef = citiesRef.where("state", "==", "CO");
// Create Observables.
var california$ = new Rx.Subject();
var colorado$ = new Rx.Subject();
// When either California OR Colorado values are emitted from their queries,
// combine both observables
var californiaOrColorado$ = Rx.Observable.combineLatest(california$, colorado$).switchMap((cities) => {
// Destructure the values to combine a single array.
var [californiaCities, coloradoCities] = cities;
var combined = [
//spread the arrays out to combine as one array
...californiaCities,
...coloradoCities
]
// Subscribe to the latest stream that contains both
// California and Colorado.
californiaOrColorado$.subscribe((result) => {
// Output to UI.
var citiesEle = document.getElementById('cities');
result.forEach(city => {
var itemEle = document.createElement("li");
itemEle.textContent = city.name;
citiesEle.appendChild(itemEle);
});
caOrCoCities$: Observable<City[]>;
...
const californiaRef = this.angularFirestore
.collection("cities", ref => ref.where("state","==","CA"));
const coloradoRef = this.angularFirestore
.collection("cities", ref => ref.where("state","==","CO"));
this.caOrCoCities$ = Observable
.combineLatest(californiaRef.valueChanges(),
coloradoRef.valueChanges())
.switchMap(cities => {
<ul>
<li *ngFor="let cities of caOrCoCities$ | async as caOrCoCities">
...
</li>
</ul>
import { collection } from 'rxfire/firestore';
import { map } from 'rxjs/operators';
// Query for California
var californiaRef = citiesRef.where("state", "==", "CA");
// Query for Colorado
var coloradoRef = citiesRef.where("state", "==", "CO");
// Create Observables ready for subscribe().
import { combineLatest } from 'rxjs';
var californiaOrColorado$ = combineLatest(california$, colorado$)
.pipe(
map((cities) => {
// Destructure the values to combine a single array.
var [californiaCities, coloradoCities] = cities;
return [
//spread the arrays out to combine as one array
...californiaCities,
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
const firebase = admin.initializeApp();
export const deletePhotos = functions.firestore
.document("posts/{postId}")
.onDelete((snap, context) => {
const { postId } = context.params;
const bucket = firebase.storage().bucket();