Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

firestore get first document in collection and delete it

// you need a reference field like timestamp
// this will work in a cloud function
return admin.firestore().collection("yourCollection")
.orderBy("yourTimestamp", "desc")
.limit(1)
.get()
.then(querySnapshot => {
    if (!querySnapshot.empty) {
        //We know there is one doc in the querySnapshot
        const queryDocumentSnapshot = querySnapshot.docs[0];
        return queryDocumentSnapshot.ref.delete();
    } else {
        console.log("No document corresponding to the query!");
        return null;
    }
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #firestore #document #collection #delete
ADD COMMENT
Topic
Name
9+3 =