Created
December 22, 2019 04:00
-
-
Save danahartweg/4969fb5a66307036d59de95f3946dc5d to your computer and use it in GitHub Desktop.
Creating homestead indices - Efficiently managing large Cloud Firestore lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { firestore } from 'firebase-functions'; | |
import { getFirestore } from '../admin'; | |
import { IndexMeta } from '../types'; | |
/** | |
* When a new homestead is created we want to create | |
* the needed indices so they can be immediately accessed. | |
*/ | |
export const createIndicesForHomestead = firestore | |
.document('homesteads/{homesteadId}') | |
.onCreate(async (_, context) => { | |
const db = getFirestore(); | |
const batch = db.batch(); | |
const indicesCollection = db.collection('indices'); | |
batch.set(indicesCollection.doc(), { | |
indexName: 'plant-varieties', | |
isFull: false, | |
parentId: context.params.homesteadId, | |
} as IndexMeta); | |
/** additional indices to be added later */ | |
return batch.commit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment