Streaming data from Firebase Realtime Database










-1















I have over 20k documents in my Realtime Database. I need to stream them, but I'm not even sure how to get started with it. This is kind of what I was trying to go for



sendEmail.get('/:types/:message', cors(), async (req, res, next) => 
console.log(5);
const types = JSON.parse(req.params.types);
console.log('types', types);
let recipients = ;
let mails = ;
if (types.includes('students'))
console.log(1);
const tmpUsers = await admin.database().ref('Users').orderByChild('student').equalTo(true).once('value').then(r => r.val()).catch(e => console.log(e));
recipients = recipients.concat(tmpUsers);

if (types.includes('solvers'))
console.log(2);
let tmpUsers = await admin.database().ref('Users').orderByChild('userType').equalTo('person').once('value').then(r => r.val()).catch(e => console.log(e));
tmpUsers = tmpUsers.concat(arrayFromObject(await admin.database().ref('Users').orderByChild('userType').equalTo('company').once('value').then(r => r.val()).catch(e => console.log(e))));
recipients = recipients.concat(tmpUsers);

);


But this code causes my server to run out of memory. Someone suggested streams in my previous question, but as much as I like the idea, I have no idea how to actually do the streaming. I know it should be something like:



const fs = require('fs');
const readStream = fs.createReadStream('path goes here');
const data = ;
readStream.on('data', chunk =>
data.push(chunk);
)
readStream.on('end', () =>
console.log(data);
res.end(data);
);


But how on earth do I pass a firebase query into the path?



I tried this, but it said Argument type Promise is not assignable to parameter type PathLike, which makes sense, but how do I get around it?



const users = fs.createReadStream(admin.database().ref('News').once('value').then(r => r.val()))


To summarize: How do I stream data from a Firebase realtime database?



Edit:
How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different










share|improve this question
























  • How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different

    – Alex Ironside
    Nov 14 '18 at 14:34
















-1















I have over 20k documents in my Realtime Database. I need to stream them, but I'm not even sure how to get started with it. This is kind of what I was trying to go for



sendEmail.get('/:types/:message', cors(), async (req, res, next) => 
console.log(5);
const types = JSON.parse(req.params.types);
console.log('types', types);
let recipients = ;
let mails = ;
if (types.includes('students'))
console.log(1);
const tmpUsers = await admin.database().ref('Users').orderByChild('student').equalTo(true).once('value').then(r => r.val()).catch(e => console.log(e));
recipients = recipients.concat(tmpUsers);

if (types.includes('solvers'))
console.log(2);
let tmpUsers = await admin.database().ref('Users').orderByChild('userType').equalTo('person').once('value').then(r => r.val()).catch(e => console.log(e));
tmpUsers = tmpUsers.concat(arrayFromObject(await admin.database().ref('Users').orderByChild('userType').equalTo('company').once('value').then(r => r.val()).catch(e => console.log(e))));
recipients = recipients.concat(tmpUsers);

);


But this code causes my server to run out of memory. Someone suggested streams in my previous question, but as much as I like the idea, I have no idea how to actually do the streaming. I know it should be something like:



const fs = require('fs');
const readStream = fs.createReadStream('path goes here');
const data = ;
readStream.on('data', chunk =>
data.push(chunk);
)
readStream.on('end', () =>
console.log(data);
res.end(data);
);


But how on earth do I pass a firebase query into the path?



I tried this, but it said Argument type Promise is not assignable to parameter type PathLike, which makes sense, but how do I get around it?



const users = fs.createReadStream(admin.database().ref('News').once('value').then(r => r.val()))


To summarize: How do I stream data from a Firebase realtime database?



Edit:
How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different










share|improve this question
























  • How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different

    – Alex Ironside
    Nov 14 '18 at 14:34














-1












-1








-1








I have over 20k documents in my Realtime Database. I need to stream them, but I'm not even sure how to get started with it. This is kind of what I was trying to go for



sendEmail.get('/:types/:message', cors(), async (req, res, next) => 
console.log(5);
const types = JSON.parse(req.params.types);
console.log('types', types);
let recipients = ;
let mails = ;
if (types.includes('students'))
console.log(1);
const tmpUsers = await admin.database().ref('Users').orderByChild('student').equalTo(true).once('value').then(r => r.val()).catch(e => console.log(e));
recipients = recipients.concat(tmpUsers);

if (types.includes('solvers'))
console.log(2);
let tmpUsers = await admin.database().ref('Users').orderByChild('userType').equalTo('person').once('value').then(r => r.val()).catch(e => console.log(e));
tmpUsers = tmpUsers.concat(arrayFromObject(await admin.database().ref('Users').orderByChild('userType').equalTo('company').once('value').then(r => r.val()).catch(e => console.log(e))));
recipients = recipients.concat(tmpUsers);

);


But this code causes my server to run out of memory. Someone suggested streams in my previous question, but as much as I like the idea, I have no idea how to actually do the streaming. I know it should be something like:



const fs = require('fs');
const readStream = fs.createReadStream('path goes here');
const data = ;
readStream.on('data', chunk =>
data.push(chunk);
)
readStream.on('end', () =>
console.log(data);
res.end(data);
);


But how on earth do I pass a firebase query into the path?



I tried this, but it said Argument type Promise is not assignable to parameter type PathLike, which makes sense, but how do I get around it?



const users = fs.createReadStream(admin.database().ref('News').once('value').then(r => r.val()))


To summarize: How do I stream data from a Firebase realtime database?



Edit:
How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different










share|improve this question
















I have over 20k documents in my Realtime Database. I need to stream them, but I'm not even sure how to get started with it. This is kind of what I was trying to go for



sendEmail.get('/:types/:message', cors(), async (req, res, next) => 
console.log(5);
const types = JSON.parse(req.params.types);
console.log('types', types);
let recipients = ;
let mails = ;
if (types.includes('students'))
console.log(1);
const tmpUsers = await admin.database().ref('Users').orderByChild('student').equalTo(true).once('value').then(r => r.val()).catch(e => console.log(e));
recipients = recipients.concat(tmpUsers);

if (types.includes('solvers'))
console.log(2);
let tmpUsers = await admin.database().ref('Users').orderByChild('userType').equalTo('person').once('value').then(r => r.val()).catch(e => console.log(e));
tmpUsers = tmpUsers.concat(arrayFromObject(await admin.database().ref('Users').orderByChild('userType').equalTo('company').once('value').then(r => r.val()).catch(e => console.log(e))));
recipients = recipients.concat(tmpUsers);

);


But this code causes my server to run out of memory. Someone suggested streams in my previous question, but as much as I like the idea, I have no idea how to actually do the streaming. I know it should be something like:



const fs = require('fs');
const readStream = fs.createReadStream('path goes here');
const data = ;
readStream.on('data', chunk =>
data.push(chunk);
)
readStream.on('end', () =>
console.log(data);
res.end(data);
);


But how on earth do I pass a firebase query into the path?



I tried this, but it said Argument type Promise is not assignable to parameter type PathLike, which makes sense, but how do I get around it?



const users = fs.createReadStream(admin.database().ref('News').once('value').then(r => r.val()))


To summarize: How do I stream data from a Firebase realtime database?



Edit:
How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different







javascript node.js firebase firebase-realtime-database stream






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 14:35







Alex Ironside

















asked Nov 14 '18 at 9:56









Alex IronsideAlex Ironside

1,078726




1,078726












  • How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different

    – Alex Ironside
    Nov 14 '18 at 14:34


















  • How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different

    – Alex Ironside
    Nov 14 '18 at 14:34

















How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different

– Alex Ironside
Nov 14 '18 at 14:34






How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different

– Alex Ironside
Nov 14 '18 at 14:34













1 Answer
1






active

oldest

votes


















1














Realtime Database doesn't have any streaming APIs. When you perform a query, the entire result set is always loaded into memory in one shot.



A possible alternative is to page through the results using limitToFirst() along with some query ordering that allows you to perform a subsequent query after the first batch of items is processed, picking up where the last query left off.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297378%2fstreaming-data-from-firebase-realtime-database%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Realtime Database doesn't have any streaming APIs. When you perform a query, the entire result set is always loaded into memory in one shot.



    A possible alternative is to page through the results using limitToFirst() along with some query ordering that allows you to perform a subsequent query after the first batch of items is processed, picking up where the last query left off.






    share|improve this answer



























      1














      Realtime Database doesn't have any streaming APIs. When you perform a query, the entire result set is always loaded into memory in one shot.



      A possible alternative is to page through the results using limitToFirst() along with some query ordering that allows you to perform a subsequent query after the first batch of items is processed, picking up where the last query left off.






      share|improve this answer

























        1












        1








        1







        Realtime Database doesn't have any streaming APIs. When you perform a query, the entire result set is always loaded into memory in one shot.



        A possible alternative is to page through the results using limitToFirst() along with some query ordering that allows you to perform a subsequent query after the first batch of items is processed, picking up where the last query left off.






        share|improve this answer













        Realtime Database doesn't have any streaming APIs. When you perform a query, the entire result set is always loaded into memory in one shot.



        A possible alternative is to page through the results using limitToFirst() along with some query ordering that allows you to perform a subsequent query after the first batch of items is processed, picking up where the last query left off.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 17:06









        Doug StevensonDoug Stevenson

        79.3k994112




        79.3k994112





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297378%2fstreaming-data-from-firebase-realtime-database%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20