Utility for making changes across an entire Firestore collection.
import fireaway, { fieldToField } from 'fireaway'
import admin from 'firebase-admin'
// After initialising admin
const db = admin.firestore()
const fieldValue = admin.firestore.FieldValue
const migration = fireaway({
db,
fieldValue
})
migration('collectionName', fieldToField('formerFieldName', 'newFieldName'))
Pass in your Firestore db and fieldValue to configure fireaway. This should return a function, that takes a collection name and a handler.
Creates a new field accross an entire collection.
Parameters
field name {String}
Name of the field.
field value {String | Number}
default value to assign
Renames a field.
Parameters
former name {String}
Former name
new name {String}
New name
Renames an existing field or creates it if it is missing.
Parameters
former name {String}
Former name
new name {String}
New name
default value {String | Number}
Default value
Removes a field from all documents in a collection.
Parameters
field name {String}
Name of field to remove
Creates a sub-collection accross an entire collection.
Parameters
value {Object}
Document fields
sub collection name {String}
Name fo subcollection
Write your own handlers to carry out batch operations.
function customHandler('argument(s) you will need'){
return (batch, entries, collection) => {
entries.forEach((entry) => {
const ref = collection.doc(entry.id)
// stuff you want to do accross all docs with args
batch.update(ref, { fieldYouWant: 'Value you derived' })
})
}
}
migration('collectionName', customHandler('parameter(s) you need'))