Helpers used for common admin task on Firestore databases.
- Install the package via:
$ npm install --save admin-utils-firestore
- Init admin-utils-firestore via:
import {FirestoreAdminUtils} from 'admin-utils-firestore';
const adminUtilsFirestore = new FirestoreAdminUtils();
Target a firestore collection reference via:
const colRef = db.collection('test');
const utilColRef = adminUtilsFirestore.ref(colRef);
-
deleteFieldDocs
For each documents in a referenced collection performs a delete operation of the old field key
utilColRef.deleteFieldDocs('fieldKeyToDelete')
-
importDocs
Allow to import documents in a collection using a bulk operation
utilColRef.importDocs({uid: '1'}, {uid: '2', name: 'Giovanni'})
-
renameFieldDocs
For each documents in a referenced collection performs a update operation of the new field key, and then performs, if it exist, a remove operation of the old field key
utilColRef.renameFieldDocs({oldFieldKey: 'newFieldKey'})
Target a firestore document reference via:
const docRef = db.collection('users').doc('xyz');
const utilDocRef = adminUtilsFirestore.ref(docRef);
-
renameField
For the referenced document performs a update operation of the new field key, and then performs, if it exist, a remove operation of the old field key
utilDocRef.renameField({oldFieldKey: 'newFieldKey'})
This in a unofficial library for Firestore (https://firebase.google.com/docs/firestore) we recommend replicating the operation, where it's possible, in a test project to check if the output is what expected before to run any operation in a production environment. Thanks for using and testing this library!
For bugs and feature requests please Create an Issue.