[AngularFire2 & Firestore] Example for collection and doc
import {Injectable} from '@angular/core';
import {Skill} from '../models/skills';
import {AuthService} from '../../auth/services/auth.service';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/catch';
import {Observable} from 'rxjs/Observable';
import {AngularFirestore, AngularFirestoreCollection} from 'angularfire2/firestore';
@Injectable()
export class SkillsService {
skillCollection: AngularFirestoreCollection<Skill>;
skills: Observable<Skill[]>;
events: Observable<any>;
constructor(private afs: AngularFirestore,
private authService: AuthService) {
this.skillCollection = afs.collection(`users/${this.uid}/skills`,
ref => ref.orderBy('name').limit(10));
this.events = this.skillCollection.auditTrail();
}
get uid() {
return this.authService.user.uid;
}
getSkills(): Observable<Skill[]> {
return this.skillCollection
.snapshotChanges()
.startWith([]) // To solve the snapshotChange doesn't fire for empty data
.map((actions) =>
actions.map(({payload}) => ({id: payload.doc.id, ...payload.doc.data()} as Skill))
);
}
getSkill(key): Observable<Skill> {
return this.afs.doc(`users/${this.uid}/skills/${key}`)
.snapshotChanges()
.map(({payload}) => ({id: payload.id, ...payload.data()} as Skill));
}
addSkill(skill: Skill) {
return this.skillCollection.add(skill);
}
updateSkill(key: string, skill: Partial<Skill>) {
return this.afs.doc<Skill>(`users/${this.uid}/skills/${key}`).update(skill);
}
removeSkill(key: string) {
return this.afs.doc<Skill>(`users/${this.uid}/skills/${key}`).delete();
}
}
[AngularFire2 & Firestore] Example for collection and doc的更多相关文章
- [AngularFire] Firebase OAuth Login With Custom Firestore User Data
import { NgModule } from '@angular/core'; import { AuthService } from './auth.service'; import { Ang ...
- doc.update
db.collection('todos').doc('todo-identifiant-aleatoire').update({ // data 传入需要局部更新的数据 data: { // 表示将 ...
- 微信小程序云数据库——where查询和doc查询区别
用法 条件查询where 我们也可以一次性获取多条记录.通过调用集合上的 where 方法可以指定查询条件,再调用 get 方法即可只返回满足指定查询条件的记录,比如获取用户的所有未完成的待办事项,用 ...
- React Native纯干货总结
随着项目也渐渐到了尾声,之前的项目是mobile开发,采用的是React Native.为即将要开始做RN项目或者已经做过的小伙伴可以参考借鉴,也顺便自己做一下之前项目的总结. 文章比较长,可以选择自 ...
- MongoDB Java Driver操作指南
MongoDB为Java提供了非常丰富的API操作,相比关系型数据库,这种NoSQL本身的数据也有点面向对象的意思,所以对于Java来说,Mongo的数据结构更加友好. MongoDB在今年做了一次重 ...
- MongoDB 聚合操作
在MongoDB中,有两种方式计算聚合:Pipeline 和 MapReduce.Pipeline查询速度快于MapReduce,但是MapReduce的强大之处在于能够在多台Server上并行执行复 ...
- [译] MongoDB Java异步驱动快速指南
导读 mongodb-java-driver是mongodb的Java驱动项目. 本文是对MongoDB-java-driver官方文档 MongoDB Async Driver Quick Tour ...
- 10 行 Python 代码写的模糊查询
导语: 模糊匹配可以算是现代编辑器(在选择要打开的文件时)的一个必备特性了,它所做的就是根据用户输入的部分内容,猜测用户想要的文件名,并提供一个推荐列表供用户选择. 样例如下: Vim (Ctrl-P ...
- MongoDB C Driver使用教程
MongoDB C Driver使用教程 转载请注明出处http://www.cnblogs.com/oloroso/ 本指南提供简介 MongoDB C 驱动程序. 在 C API 的详细信息,请参 ...
随机推荐
- java uploadify 上传组件使用方法
!!!声明 1-3 是jsp页面所写内容 文中需要的util 参见百度云 http://pan.baidu.com/s/1kV0gqBt 如已失效 请加QQ1940978083 1.首先引入 ...
- WHU 1552 Seats 枚举
题意: 有一个年级中7个班的n个学生. 一天,他们毫无顺序的站成一排.请计算最小的交换次数,使得 相同班的同学都站在一起. (只有站在一起的人才能交换) 思路: 如果知道班级的最终排列就能在很短的时间 ...
- 洛谷 P1071 潜伏者
P1071 潜伏者 题目描述 R 国和 S 国正陷入战火之中,双方都互派间谍,潜入对方内部,伺机行动.历尽艰险后,潜伏于 S 国的 R 国间谍小 C 终于摸清了 S 国军用密码的编码规则: 1. S ...
- Android——4.2.2 文件系统文件夹分析
近期公司要整android内部培训,分配给我写个培训文档.这里记录例如以下: 撰写不易,转载请注明出处:http://blog.csdn.net/jscese/article/details/4089 ...
- hdoj--2955--Robberies(背包好题)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 水 hdu5208 2015-04-20 21:03 36人阅读 评论(0) 收藏
题意: 选择数列中两个数,使得最大公约数最大 分析: 类似筛选法,因为数值不大,可以用b[i]计算i是多少个数的因子.最后取最大的i即可. #include <bits/stdc++.h> ...
- b模式处理文件
1.读 f=open('cheng','rb') date=f.read() print(date.decode()) 2.写 f=open('cheng','ab') f.write('chengz ...
- Swift学习笔记(1)--基本语法
1.分号; 1>Swift不要求每个语句后面跟一个分号作为语句结束的标识,如果加上也可以,看个人喜好 2>在一行中写了两句执行语句,需要用分号隔开,比如 let x = 0; printl ...
- [Python] Understand Mutable vs. Immutable objects in Python
In this lesson, you will learn what mutable and immutable objects are, and the difference between th ...
- UVA 12508 - Triangles in the Grid(计数问题)
12508 - Triangles in the Grid 题目链接 题意:给定一个n∗m格子的矩阵,然后给定A,B.问能找到几个面积在A到B之间的三角形. 思路:枚举每一个子矩阵,然后求[0,A]的 ...