this.db.collection(collection)
.valueChanges()
.subscribe();
this.db.collection(collection)
.valueChanges().subscribe(
snaps => {
const collection = snaps.map( snap => {
return {
id: snap.payload.doc.id,
...snap.payload.doc.data()
}
}
}
);
this.db.collection(collection)
.stateChanges().subscribe(
snaps => {
const collection = snaps.map( snap => {
return {
id: snap.payload.doc.id,
...snap.payload.doc.data()
}
}
}
this.db.collection(collection, ref => {
return ref.orderBy(param).where(param, "==", what)
})
.snapshotChanges()...}}
...
.where(param, "== , >, <= or any", what)...
.where(param, "array-contains", what)...
.startAt(number).endAt(number)... (first element included)
.startAfter(number).endAt(number)...(first element is not included)
this.db.doc(collection/id).set(changes)...
this.db.doc(collection/id).update(changes)...
const fRef = this.db.doc(collection/id).ref;
const oRef = this.db.doc(collection/id).ref;
const batch = this.db.firestore.batch();
batch.update(fRef, { updates });
...
const batch$ = of(batch.commit());
batch$.subscribe();
const d = this.db
.collection(collection);
return d.doc(id).delete();
private storage: AngularFireStorage;
...
upload(event) {
const file: File = event.target.files[0];
const path = `collection/id/filename`;
const task = this.storage.upload (path, file);
task.snapshotChanges().subscribe();
}
...
task.percentageChanges() - get current upload percentage
profileUrl: Observable<string | null>;
constructor(private storage: AngularFireStorage) {
const ref = this.storage.ref('users/davideast.jpg');
this.profileUrl = ref.getDownloadURL();
}
...
meta: Observable<any>;
constructor(private storage: AngularFireStorage) {
const ref = this.storage.ref('users/davideast.jpg');
this.meta = ref.getMetadata();
}
...
uploadFile(event) {
const file = event.target.files[0];
const filePath = 'name-your-file-path-here';
const ref = this.storage.ref(filePath);
const task = ref.put(file, { customMetadata: { blah: 'blah' } });
}
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.