FirestoreRef
Creates a Firebase Cloud Firestore doc or collection reference using a "URL like" path string format.
Installation and use
npm install --save firestore-ref
- Import the lib
// ES6 modules; // cjs modulesconst firestoreRef = ;
- Import Firebase and Firestore libs, connect your app, and instatiate the reference creator using your firestore reference
// example for ES6 modules;; // replace with the data from your appconst config = apiKey: "AIasdfYiJoJMxasdfaKcI-asdf40" authDomain: "theproject.firebaseapp.com" databaseURL: "https://theproject.firebaseio.com" projectId: "theproject" storageBucket: "theproject.appspot.com" messagingSenderId: "00000000"; const firestore = firebase; const ref = ;
- Create collection or doc references
// 1. Using a string path: // # collection firestore.collection('carbrands')const carBrandsRef = ;// # doc firestore.collection('carbrands').doc('chevrolet')const chevroletRef = ; // 2. Concatenating a prevously created firestore reference with a string path: // # doc firestore.collection('carbrands').doc('chevrolet')const carBrandsRef = firestore;const chevroletRef = ;// the same example using firestoreRef to create a firestore reference and concatenatingconst carBrandsRef = ;const chevroletRef = ; // 3. You can create deep references until the level Firebase permits // # doc firestore.collection('carbrands').doc('chevrolet').collection('models').doc('camaro')const camaroRef = ;// # doc firestore.collection('carbrands').doc('chevrolet').collection('models').doc('camaro').collection('editions').doc('3.0-turbo')const camaroRef = ;// the above example using firestoreRef to create a firestore reference and concatenatingconst camaroModelRef = ;const camaroTurboEditionRef = ;
License
MIT