You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constfunctions=require("firebase-functions");constadmin=require("firebase-admin");admin.initializeApp(functions.config().firebase);constCOLLECTION_NAME=functions.config().db.collection;letdb=admin.firestore();letcollection=db.collection(COLLECTION_NAME);// Use doc, get, set, update and delete methods from collection.
Third-Party ORM/ODM
Typesaurus ODM
const{ collection, add, set, update, get, remove, all, query, where }=require('typesaurus');constfunctions=require("firebase-functions");constadmin=require("firebase-admin");admin.initializeApp(functions.config().firebase);constCOLLECTION_NAME=functions.config().db.collection;// ModeltypeUser={name: string}constusers=collection<User>(COLLECTION_NAME)// Add a document to a collection with auto-generated idadd(users,{name: 'Sasha'})//=> Promise<Doc<User>>// Set or overwrite a document with given idset(users,'42',{name: 'Sasha'})//=> Promise<Doc<User>>// Update a document with given idupdate(users,'42',{name: 'Sasha'})//=> Promise<void>// Get a document with given idget(users,'42')//=> Promise<Doc<User> | null>// Get all documents in a collectionall(users)//=> Promise<Doc<User>[]>// Query collectionquery(users,[where('name','===','Sasha')])//=> Promise<Doc<User>[]>// Remove a document with given idremove(users,'42')//=> Promise<void>