When building a query to select the latest data in firebase, all data is selected instead of the amount specified in the argument. I noticed that this problem also exists in the first message selection. I don’t know about other query parameters, I didn’t use them.
export const messagesRef = ref(database, `messages/`)
export async function getMessages() {
return new Promise((resolve) => {
const data = []
const lastMessages = query(messagesRef, limitToFirst(10))
const snapshot = get(lastMessages).then(() => {
Object.entries(snapshot).forEach(([key, value]) => {
data.push({ ...value, key: key })
})
resolve(data)
})
})
}
Honestly, I don’t even know what to do here. I looked at the firebase documentation, but didn’t understand what I did wrong. I asked copylot and dug around in stackoverflow.
Nikolai Quasarka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.