javascriptmongodbdisplayfrontpage

Trouble displaying data from MongoDb by using js/express.js,


I have a hard time displaying data from my MongoDB to my frontpage. I can see that I get the right number of items in my collection but it tells me [object Object] when I try to display the chosen data. Can anyone help? Thank you Code for getting data from the collection "title"

Call for displaying the 1 element in the title array

What the browser tells me


Solution

  • You are trying to display a whole object which results in [object Object]. You have to give your HTML a string like result[0].title (assuming you have a field title in your object)

    You can also display the whole object with JSON.stringify(result[0]) in JS.