Firestore Sweet

Firestore Sweet

  • Tutorial
  • API
  • Github

›Read

Tutorial

  • Getting Started

Read

  • get
  • on
  • ref

Write

  • add
  • set
  • upsert
  • update
  • delete

FieldValue

  • inc
  • del
  • ts
  • union
  • remove

Atomic & Bulk

  • tx
  • batch

get

firestore-sweet is smart enough to figure out whether the argument is for collection doc where orderBy or limit based on the argument type and the position.

get doc

const user = await db.get("users", "bob")
// equivalent firestore
const user = (await fs.collection("users").doc("bob").get()).data()

get collection

const users = await db.get("users")
// [{"name": "Bob", "age": 35}, {"name": "Alice", "age": 20}]
// equivalent firestore
let users = []
(await fs.collection("users").get())).forEach((ss)=>{
  users.push(ss.data())
})

get collection with where

const users = await db.get("users", ["age", "==", 30])
// equivalent firestore
let users = []
(await fs.collection("users").where("age", "==", 30).get())).forEach((ss)=>{
  users.push(ss.data())
})

get collection with limit

const users = await db.get("users", 5)
// equivalent firestore
let users = []
(await fs.collection("users").limit(5).get())).forEach((ss)=>{
  users.push(ss.data())
})

get collection with orderBy

const users = await db.get("users", ["age", "desc"])
// equivalent firestore
let users = []
(await fs.collection("users").orderBy("age", "desc").get())).forEach((ss)=>{
  users.push(ss.data())
})

get collection with orderBy and startAt

const users = await db.get("users", ["age", "desc"], ["startAt", 30])
// equivalent firestore
let users = []
(await fs.collection("users").orderBy("age", "desc").startAt(30).get())).forEach((ss)=>{
  users.push(ss.data())
})

startAt startAfter endAt endBefore all work the same way.

get collection with document id and data

const users = await db.getK("users")
// {"bob": {"name": "Bob", "age": 35}, "alice": {"name": "Alice", "age": 20 }}
// equivalent firestore
let users = {}
(await fs.collection("users").get())).forEach((ss)=>{
  users[ss.id] = ss.data()
})

get collection with document id, data and snapshot

const users = await db.getS("users")
// equivalent firestore
let users = []
(await fs.collection("users").get())).forEach((ss)=>{
  users.push({ss: ss, data: ss.data(), id: ss.id})
})
← Getting Startedon →
  • get doc
  • get collection
  • get collection with where
  • get collection with limit
  • get collection with orderBy
  • get collection with orderBy and startAt
  • get collection with document id and data
  • get collection with document id, data and snapshot
Firestore Sweet
Docs
Getting StartedAPI Reference
Who's Using Firesotre Sweet ?
WARASHIBEALISCHOOLcrypvoVePress
Where to Find Me ?
ALIS BlogGitHubStar
Follow @ocrybit
Copyright © 2020 Tomoya Nagasawa