On photo below you can see my data structure.
I want to get the required data from the messages object in one request. For example:
firebase.database().ref('messages/' + "-Me4yNAigYmM5_PhuiIS", 'messages/' + -Me4yNoy8n971XMwnxqP).get();
expected output:
{
-Me4yNAigYmM5_PhuiIS: {
text: example;
},
-Me4yNoy8n971XMwnxqP: {
text: example2;
},
}
I got out of the situation like this:
useEffect(() => {
const usersMessages = firebase.database().ref("users/" + userUid + "/messages");
usersMessages.on('value', async (snapshot) => {
let usersMessages = [];
const messages = (await firebase.database().ref("messages/").get()).val();
snapshot.val().map(messageId => {
usersMessages.push(messages[messageId]);
});
});
}, []);
How correct is it to constantly load all messages of all users? Is there a way to get only the required messages from Firestone in one request, knowing a few message IDs?