I have my Firestore structure as follows:
entries > {entryUIDs} > pnum
where entries is the collection and entryUIDs are all the documents.
I want to display all of my data in the entries collection in order of the pnum, which starts at 1 and every document has a number increased by one.
I want to be able to display it on a simple html site where each document is ordered by the pnum field.
For now I'm testing this simply using:
store.collection('entries').get().then(snapshot => {
setupSite(snapshot.docs);
});
const setupSite = (data) => {
let html = ``;
data.forEach(doc => {
const entry = doc.data();
const list = `<a href="${entry.path}">${entry.title}</a>`;
html = list;
});
document.body.innerHTML = html
}
Any help on how to order these documents would really help, as at the moment they are displayed by their Firestore Document UID.
CodePudding user response:
Try using orderBy while querying
store.collection('entries').orderBy("pnum", "asce").get().then(snapshot => {
setupSite(snapshot.docs);
});