i am trying to delete a group of documents from a query using cloud functions. The cloud function is called and exits with status ok but the documents are not deleted. What could be the issue.
exports.deleteExpiredSellerPosts = functions.firestore
.document('sellerPost/{post}')
.onCreate(async(snapshot,context)=>{
const now=snapshot.updateTime
const post=snapshot.data();
const seller=post.seller;
const postsToDelete = await admin.firestore()
.collection('sellerPost')
.where("seller", "==" ,seller)
.orderBy('expireTime','desc')
.endAt([now])
postsToDelete.get().then(function(querySnap){
querySnap.forEach(function(doc){
console.log(doc);
doc.ref.delete();
})
})
console.log('Success');
return 0;
})
I receive no error on console but documents are not deleted.
.endAt([now])in your query is giving the expected results? What do you get if you doconst postsToDelete = admin.firestore().collection('sellerPost').where("seller", "==", seller).orderBy('expireTime','desc').endAt([now]); const snap = await postsToDelete.get(); console.log(snap.size); return null;