npm.io
0.1.6 • Published 6 years ago

admin-utils-firestore

Licence
MIT
Version
0.1.6
Deps
2
Size
14 kB
Vulns
1
Weekly
0
Stars
21
DeprecatedThis package is deprecated

Admin Utils Firestore

npm Travis NPM Code Style: Google


Helpers used for common admin task on Firestore databases.

Installation:

  • 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();

Documentation:

Collections

Target a firestore collection reference via:

const colRef = db.collection('test');
const utilColRef = adminUtilsFirestore.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 = adminUtilsFirestore.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'})

Just a reminder

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!

Contributing

For bugs and feature requests please Create an Issue.

Keywords