0.1.0 • Published 4 years ago

firestore-admin-utils v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

npm License Travis Code Style: Google

Unofficial library Utils class for Firestore (https://firebase.google.com/docs/firestore) We recommend replicating the operation, where it's possible, in a test project to avoid accidental data compromises and check if the output is what expected before to run any operation in a production environment.

Installation:
$ npm install --save firestore-admin-utils-js

Init firestore-admin-utils via:

import {FirestoreAdminUtils} from 'firestore-admin-utils';
const firestoreAdminUtils = new FirestoreAdminUtils();
Collections

Target a firestore collection reference via:

const colRef = db.collection('test');
const utilColRef = firestoreAdminUtils.ref(colRef);
API
  • 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'})
Documents

Target a firestore document reference via:

const docRef = db.collection('users').doc('xyz');
const utilDocRef = firestoreAdminUtils.ref(docRef);
API
  • 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'})
0.1.0

4 years ago