Skip to content

Commit

Permalink
firstDocument fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Dorgans committed May 1, 2018
1 parent 28ae38e commit 0e69c81
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/Firestore/FIRQuery+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ extension Reactive where Base: Query {
* Reads the first document matching this query.
*/
public func getFirstDocument() -> Observable<QueryDocumentSnapshot> {
return self.getDocuments()
return self.base.limit(to: 1)
.rx
.getDocuments()
.map { snapshot in
guard let document = snapshot.documents.first(where: { $0.exists }) else {
throw NSError(domain: FirestoreErrorDomain, code: FirestoreErrorCode.notFound.rawValue, userInfo: nil)
Expand Down

0 comments on commit 0e69c81

Please sign in to comment.