import admin , { ServiceAccount } from 'firebase-admin' ; import { FirestoreSimple } from '../src' ; process . env . GCLOUD_PROJECT = 'firestore-simple-test' ; process . env . FIRESTORE_EMULATOR_HOST = 'localhost:8080' ; admin . initializeApp ( { } ) ; const firestore = admin . firestore ( ) ; const ROOT_PATH = 'example/admin_collection_group' ; interface Review { id : string ; userId : string ; text : string ; created : Date ; } const userNames = [ 'alice' , 'bob' , 'john' ] ; const collectionId = 'review' ; const main = async ( ) : Promise < void > => { await firestore . collection ( `${ ROOT_PATH }/user/alice/${ collectionId }` ) . add ( { userId : 'alice' , text : 'aaa' , created : admin . firestore . FieldValue . serverTimestamp ( ) } ) ; await firestore . collection ( `${ ROOT_PATH }/user/bob/${ collectionId }` ) . add ( { userId : 'bob' , text : 'bbb' , created : admin . firestore . FieldValue . serverTimestamp ( ) } ) ; await firestore . collection ( `${ ROOT_PATH }/user/john/${ collectionId }` ) . add ( { userId : 'john' , text : 'ccc' , created : admin . firestore . FieldValue . serverTimestamp ( ) } ) ; const firestoreSimple = new FirestoreSimple ( firestore ) ; const reviewCollectionGroup = firestoreSimple . collectionGroup < Review > ( { collectionId : 'review' , decode : ( doc ) => { return { id : doc . id , userId : doc . userId , text : doc . text , created : doc . created . toDate ( ) } ; } } ) ; const reviews = await reviewCollectionGroup . fetch ( ) ; console . dir ( reviews ) ; for ( const user of userNames ) { const userReivewDao = firestoreSimple . collection ( { path : `${ ROOT_PATH }/user/${ user }/review` } ) ; const reviews = await userReivewDao . fetchAll ( ) ; await userReivewDao . bulkDelete ( reviews . map ( ( review ) => review . id ) ) ; } } ; main ( ) ;