Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:48:24+00:00 2026-06-08T22:48:24+00:00

I want to use data from my MongoDB for displaying on HTML code via

  • 0

I want to use data from my MongoDB for displaying on HTML code via Node.js. So far, I know how to insert information from a HTML5 formular into my MongoDB and how I read out this information – but the result of my find() is like:

[ { name: 'Mr. Banana', _id: 123aclongvalueinHEX001c000001 } ]

This is the simple result example display on my node.exe cmdshell of the function:

People.find(
    {},
    ['name'],
    function(err, docs) {
        if (!err){ 
            console.log(docs);
        }
        else { throw err;}
    }
);

People is the Mongoose schema and has some attributes, in this example I am only searching for all names with only one entity saved in People.

So the question is, and I feel like searching for it forever, how do I only extract Mr. Banana without the whole [{ name: and id}] – thing? I suppose there is some function or option for it, but I just can’t find it! I could invent a function to trim it by leftstr etc. this would be my emergency solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:48:28+00:00Added an answer on June 8, 2026 at 10:48 pm

    I’ve got the hint that mongoose has functions called querystreams. That leads to my solution.

    var Bericht = new Schema({
        name     : String
      , mail     : String
      , standort : String
      , betreff  : String
      , inhalt   : String
      , datum    : Date
    });
    var Bericht = mongoose.model('Bericht', Bericht);
    
      var stream = Bericht.find().stream()
      , names = []
      , mails = []
      , standorts = []
      , betreffs = []
      , inhalts = []
      , datums = []
      , i=0;
    
    function closeHandler() {
        function closeHandler() {
            console.log(JSON.stringify(names));
        };
         stream.on('data', function (doc) {
                if (doc.name) {
            names.push(doc.name);
            mails.push(doc.mail);
            standorts.push(doc.standort);
            betreffs.push(doc.betreff);
            inhalts.push(doc.inhalt);
            datums.push(doc.datum);
          }
        })
        stream.on('close', closeHandler) 
    

    My schema has more than names, in this case 6 attributes. After using the stream.on function, I got everything out of my database into an array like mails[1] is the mail of the second entry in my mongodb. With that, I can easily display the whole content of my database in a html by using functions. Maybe this is too much, but due of liking this board, I’ll complete this thread.

    With this function, you are building a simple table of all names as return value:

        function namestable(){
            value = "<table border='1'><tr><th>Namen</th></tr>"
            for(var i=0;i<names.length;i++){
        value+="<tr><td>"+names[i]+"</td>";
            ;}
            value+="</table>";
        return value;
        }
    

    So you just have to add this function into your nodejs, when you are building the html code:

    var body = '<html>'+
        '<head>'+
        '<meta http-equiv="Content-Type" content="text/html; '+
        'charset=UTF-8" />'+
        '</head>'+
        '<body>'+
        '<form action="/upload" method="post">'+
        namestable()+
        '<input type="submit" value="Hario" />'+
        '</form>'+
        '</body>'+
        '</html>';
    
            response.writeHead(200, {'Content-Type': 'text/html'});
            response.write(body);
            response.end();     
    

    I like 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want use some data from a website with web service. i have a
I want to use greasemonkey to scrape wiki data from Last.fm (this is not
I want to use Custom URL Scheme to transfer data from application to other
I want to use a web service and grab the data from the service.
I want to use Services(WCF/RIA /Web) to take data from Entity Data Model class
Whenever I want to get data from a plist file I use the following
I want to call a web page from Flash and use the data returned
I'm trying to insert some data from a proprietary JSON database into MongoDB for
I want to switch from MySQL to MongoDB but great data losses (more than
I want to use data from XML to populate a class: E.g. <p class=<xsl:value-of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.