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

31 Views Asked by At

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

2

There are 2 best solutions below

0
leontkp On BEST ANSWER

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.

0
tesa On

Thank you! I thought I had tried that but nope. Now it works:) Have a good day