What I want to do: I want to get the first document from my collection in the Firestore, which should be order from Z-A when it comes to "description" in the document.
The problem: It tells me "No such document!". Although it should output me 1 document.
Here is the code:
getPost();
async function getPost() {
const postRef = db.collection('posts');
const doc = await postRef.orderBy('description', 'desc').limit(1).get()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data());
}
})
.catch(err => {
console.log('Error getting document', err);
});
};